Type system
Primitive/Value types
string
number
boolean
undefined
null
undefined
is a value type that has unique valueundefined
.null
is not a type.typeof null
returns'object'
Reference types
Object
Function
Anonymous object
JavaScript does not have strongly typed system, any composed type can be described as
js
let person = {
name: 'John',
age: 18
}
1
2
3
4
2
3
4
All members except functions are called properties of an object. There are two ways to access properties.
let name = person.name;
let name = person['name'];
Just like a built-in indexer, JavaScript object has key
s that can be used to get the value of corresponding property with the same name.
Array
Array in JavaScript is object
typeof [] === 'object' // true
Function
Boring...
Falsy values
false
undefined
null
0
''
(empty string)NaN
Default value
Default value and type of a JavaScript variable is undefined
.
js
let x;
console.log(typeof x); // 'undefined'
1
2
2
Bitwise Operator
8 bits integer for example:
js
// 1 = 00000001
// 2 = 00000010
// or = 00000011
// and = 00000000
console.log(1 | 2); // 3
console.log(1 & 2); // 0
1
2
3
4
5
6
2
3
4
5
6
|
compares each digit by 1
as true
, 0
as false
, to tell the final result.