The typeof Operator in JavaScript

The typeof Operator in JavaScript

Ferenc Almasi β€’ 2020 December 10 β€’ Read time 1 min read
  • twitter
  • facebook

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:

The history of "typeof null"

What is the typeof operator in JavaScript?
If you would like to see more Webtips, follow @flowforfrank

50 JavaScript Interview Questions


  • twitter
  • facebook
Did you find this page helpful?
πŸ“š 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:



This site uses cookies We use cookies to understand visitors and create a better experience for you. By clicking on "Accept", you accept its use. To find out more, please see our privacy policy.