Example 1 — typeof null is "object"
A long-standing language quirk.
JavaScript
console.log(typeof null); How It Works
- null is not a real object.
- Check null with value === null.
The typeof operator returns a string naming the type of its operand: "string", "number", "boolean", "undefined", "object", "function", or "symbol" / "bigint".
console.log(typeof "hi");
console.log(typeof 3);
console.log(typeof true);
console.log(typeof undefined); A long-standing language quirk.
console.log(typeof null); Use Array.isArray for lists.
console.log(typeof []);
console.log(Array.isArray([])); Functions have their own typeof result.
console.log(typeof function () {}); CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful