JavaScript - The typeof operator

JavaScript - The typeof operator

Table of contents

No heading

No headings in the article.

The typeof operator returns the type of the argument. It’s useful when we want to process values of different types differently or just want to do a quick check.

A call to typeof x returns a string with the type name:

typeof undefined 
"undefined"

typeof 0 
"number"

typeof 10n
"bigint"

typeof true
"boolean"

typeof "foo"
"string"

typeof Symbol("id") 
"symbol"

typeof Math 
"object"

typeof null 
"object"

typeof alert 
"function"