A way to think about a JavaScript universe.
Value Rules
Everything is a value.
Primitive values are immutable. There is only one value in the universe for each primitive value.
Primitive values:
- Undefined
- Null
- Boolean
- Number
- Special numbers:
NaN
,Infinity
,-Infinity
,-0
- Special numbers:
- String
- Symbol
- BigInt
Non-primitive values are mutable. A new value is created for each object literal or function expression evaluation.
Non-primitive values:
- Function
- Object
A variable or a property of object points to a value. Equality means they point to the same value.
Equality Rules
Object.is(a, b)
is called “same value equality”. It can compare two objects or not. It is the same as a === b
except for:
1 | Object.is(NaN, NaN) // true |
The null
Type
1 | // null has a typeof 'object' (this is a historical bug in JavaScript) |
Semicolon Rule
Add a leading semicolon when a line starts with one of the following:
+ - / [ (
In practice:
[ (