January 2020
Intermediate to advanced
548 pages
13h 36m
English
The first thing you'll often be exposed to when you first try to detect a type in JavaScript is the typeof operator:
typeof 1; // => number
The typeof operator accepts a single operand, to its right-hand-side, and will evaluate to one of eight possible string values, depending on the value that's passed:
typeof 1; // => "number"typeof ''; // => "string"typeof {}; // => "object"typeof function(){}; // => "function"typeof undefined; // => "undefined"typeof Symbol(); // => "symbol"typeof 0n; // => "bigint"typeof true; // => boolean
If your operand is an identifier without a binding, that is, an undeclared variable, then typeof will usefully return "undefined" instead of throwing a ReferenceError like any other reference to ...
Read now
Unlock full access