What is the typeof operator?

Answer

The typeof operator returns a string indicating the type of the operand. Results: typeof "hello""string", typeof 42"number", typeof true"boolean", typeof undefined"undefined", typeof Symbol()"symbol", typeof 42n"bigint", typeof function(){}"function", typeof {}"object", typeof []"object", typeof null"object" (historical bug). To check for arrays, use Array.isArray(value). To check for null: value === null. To check for an object (excluding null): typeof value === "object" && value !== null. instanceof checks the prototype chain: [] instanceof Array is true. Object.prototype.toString.call(value) gives the most accurate type string.