Types
- Has 7 different types in Javascript
- number
- boolean
- string
- undefined
- null (primitive)
- Symbol()
- object
undefined
vsnull
undefined
is the absence of definition- In object hoisting we use
undefined
- In object hoisting we use
null
is absence of value- Types are categorized in 2 sections
- Primitive (Represents single value)
- number
- boolean
- string
- undefined
- null (primitive)
- Symbol()
- Non-Primitive
- object
- array
- function
-
Array
type -
typoOf []
returnsobject
- In JS the array is interpreted as below
js
var myArr = ['a', 'b', 'c'];
This is same as below syntax.
js
var myArr = {
0: 'a',
1: 'b',
2: 'c'
};
- Since both
object
andarray
is type ofobject
, we can determine an array by using theArray
object and itsisArray()
method.
js
console.log(Array.isArray([1, 2, 3]));
console.log(Array.isArray({}));
Here the first one will print true
and the second one false
.