Backwards & Forwards
JS is backward-compatible. Developers can write code which won’t stop running when browsers are updated.
Transpiler
Developers can write JS with new syntax then use a transpiler (Babel is a popular choice) to convert the source code to older JS version.
Example: let
is coverted to var
.
Polyfill
Developers can work with recently added API methods, then use polyfill to provide the missing methods for older browsers.
Number
Number type is double precision 64-bit, which consists of numbers between -(2^53-1) and +(2^53-1) inclusive (± 9,007,199,254,740,991). So any integer is implicitly a float.
Integers are treated as 32-bit int until they are used to perform an instruction that is valid on a Number but not on 32-bit int.
Custom Object
Comparisons
=== is described as ‘checking both the value and the type’, which is correct most of the time.
2 special cases:
For NaN
, use Number.isNaN(…)
. For -0
, use Object.is(…)
.
As for non-primitives, === compares references.
this
this
value is dynamic and depends on the execution context.
this
points to global object window
.
this
refers to the object that execute the function.
Can also use apply
to bind this to an object.
In the context of prototypes, this
will still resolve to the executed object.
Call vs Apply
A for array and C for comma.
Prototypes
A mechanism by which JS objects inherit features from another.
Object.prototype
is the most basic prototype which all objects have by default.