In the example below, we are declaring and initializing two variables named x and y with values 5 and 10.
var x = 5; var y = 10;
- Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.
var list = ; // option 1 var list = new array(); // option 2
Initialization of an Array:
var list = [1, 2, 3]; // option 1 var list = new array(1, 2, 3); // option 2
In the code snippet above we have an array with a name of "list" with three elements
1 at index 0,
2 at index 1,
3 at index 2. Arrays start from index 0. Let's see how we can access an element from an array:
var list = [1, 2, 3]; console.log(list)
And we got the first element with a value of
1. Like in the example you can access every element by its index, using
 and the index of the element inside.
- Number represents both integer and floating-point numbers.
- Boolean represents a logical entity and can have only two values:
- String type is used to represent textual data. It can be used as
- Undefined has a value of
undefinedwhen value is not assigned.
- Null can have just one value:
null. It’s just a special value that represents nothing.
- Symbol is a unique and immutable value and may be used as the key of an Object property.
- Object in computer science is an object with a value in memory which is possibly referenced by an identifier.