Type system
Primitive/Value types
stringnumberbooleanundefinednull
undefinedis a value type that has unique valueundefined.nullis not a type.typeof nullreturns'object'
Reference types
ObjectFunction
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 keys 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
falseundefinednull0''(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); // 01
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.