JS
See the Pen thecodelog.com - JS Types 1 by Deano (@deangilewicz) on CodePen.
JavaScript has the following built-in types:
- string
- number
- boolean
- null
- undefined
- object
- symbol (es6)
See the Pen thecodelog.com - JS Types 2 by Deano (@deangilewicz) on CodePen.
Be warned, there is a known “bug” for checking the type of null:
See the Pen thecodelog.com - JS Types 3 by Deano (@deangilewicz) on CodePen.
We need to use a compound condition to test for a null value:
See the Pen thecodelog.com - JS Types 4 by Deano (@deangilewicz) on CodePen.
Variables that have no value assigned, have the undefined value.
See the Pen thecodelog.com - JS Types 5 by Deano (@deangilewicz) on CodePen.
We can use the following technique when checking global variables, feature checking, or when writing “polyfill” code:
See the Pen thecodelog.com - JS Types 6 by Deano (@deangilewicz) on CodePen.
String, Number and Boolean are Primitives – they are immutable (their values are unable to be changed because they are merely values). String, Number and Boolean are Primitives – they are immutable (their values are unable to be changed because they are merely values).
When attempting to apply methods to these primitives, JavaScript (behind the scenes) will automatically use an Object wrapper around the primitive value, allowing for the use of methods on the value (the instance will be shipped out for garbage collection).
See the Pen thecodelog.com - JS Types 7 by Deano (@deangilewicz) on CodePen.
Null and undefined are also both Primitives. null represents the intentional absence of any object value. undefined represents a variable that has not been assigned a value.
See the Pen thecodelog.com - JS Types 8 by Deano (@deangilewicz) on CodePen.
JavaScript built-in types are either falsey or truthy:
See the Pen thecodelog.com - JS Types 9 by Deano (@deangilewicz) on CodePen.