
The typeof Operator in JavaScript
In JavaScript, the typeof operator can be used for getting the data type of its operand as a string:
Copied to clipboard! Playground
// The typeof operator is used for getting
// the type of its operand:
// This will return "string"
typeof '1'
// This will return "number"
typeof 1
// This will return "number"
typeof NaN
// This will return "boolean"
typeof true
// This will return "undefined"
typeof undefined
// This will return "symbol"
typeof Symbol()
// This will return "object"
typeof []
// This will return "object"
typeof null Note that the type of NaN is a number. Also the type of null is an object. If you are interested in the history of why null is an object, I highly recommend checking out the below article from 2ality:

Resources:
π More Webtips

Rocket Launch Your Career
Speed up your learning progress with our mentorship program. Join as a mentee to unlock the full potential of Webtips and get a personalized learning experience by experts to master the following frontend technologies:






