DEV Community

Cover image for Getting Started With Modern JavaScript
juliamwangi123
juliamwangi123

Posted on

Getting Started With Modern JavaScript

Introduction to modern JavaScript_

A Brief History On Javascript

JavaScript was created by Brendan Eich in 1995 it was initially known as LiveScript but later on changed to JavaScript so as to position it as a companion to java programming language.

What is JavaScript?

JavaScript is a scripting language, its one of the popular programming languages. Initially js was mainly used for making webpages interactive such as form validation, animation, etc. Nowadays, JavaScript is also used in many other areas such as server-side development, mobile app development and so on.

Basics in JavaScript

  1. Variables
  2. Datatypes
  3. comments
  4. Functions
  5. Objects
  6. Arrays

Variables

variables are containers that store data values,in JavaScript you can declare variables using 3 keyword var, let or const .JavaScript is a loosely -typed language you don't have to specify datatype when declaring variables .

var name ='jules'
const nationality = 'Kenyan'
let age = 12

Datatypes

The term datatypes refers to the type of values a program can work with.JavaScript variables can hold a number of data types

let year = 1995; // datatype is a number
let name = 'jules is a kenyan '; // datatype is a string 
let isAHoliday= true // datatype boolean ,takes true or false
const price  = 45.55 // datatype float ,a number with decimals
Enter fullscreen mode Exit fullscreen mode

Comments

comments are block of statements that don't get executed.They make our code more readable to others so be kind and comment*smiles

// this a single line comment
/* 
   this is
   a mutiple-line 
   comment

*/
Enter fullscreen mode Exit fullscreen mode

*

Functions

A function is block of code that performs a specific task.
Advantages of using functions is

  1. Can be reused- define a code once use it many times.
  2. Can use the same code many times with different arguments to produce different results
function name (){

//code to be executed
}

Enter fullscreen mode Exit fullscreen mode

Objects

JavaScript objects are variables that contain many values written in form of key:values

let student ={
    name :'jules',
    age: 12;
    height: 153
}
Enter fullscreen mode Exit fullscreen mode

Arrays

JavaScript arrays stores multiple values in a single variable

// empty array
const myList = [ ];

// array of numbers
const numberArray = [ 2, 4, 6, 8];

// array of strings
const stringArray = [ 'eat', 'work', 'sleep'];

// array with mixed data types
const newData = ['work', 'exercise', 1, true];
Enter fullscreen mode Exit fullscreen mode

Top comments (0)