Here’s a quick reference of various values and their types.
For further reference: see what types mean in Javascript and type casting in Javascript.
| Value | Type | Description |
|---|---|---|
| true | boolean | Boolean |
| 1 | number | Number |
| “1” | string | String |
| “abcd” | string | String |
| Boolean(false) | object | Boolean object |
| Number(0) | object | Number object |
| String(“abcd”) | object | String object |
| [1, 2, 3] | object | Array object |
| Object() | object | Plain object |
| {} | object | Plain object |
| function() {} | function | Function object |
Code to cross-check -
console.log(typeof true); // boolean
console.log(typeof 1); // number
console.log(typeof 3.14); // number
console.log(typeof "1"); // string
console.log(typeof "abcd"); // string
console.log(">> Objects <<");
console.log(typeof new Boolean(false)); // object
console.log(typeof new Number(0)); // object
console.log(typeof new String("abcd")); // object
console.log(typeof [1, 2, 3]); // object
console.log(typeof new Object()); // object
console.log(typeof {}); // object
console.log(typeof function() {}); // function
The only objective of the above table is to provide an overview of what you can expect when working with the loose-typing in Javascript.
Often times you don’t care about types in Javascript - I get that.