The typeof Operator
JavaScript typeof
The typeof operator returns the type of a variable, object, function or expression.
Please observe:
- The data type of NaN is number
- The data type of an array is object
- The data type of a date is object
- The data type of null is object
- The data type of an undefined variable is undefined
Example
typeof "John"
typeof 3.14
typeof NaN
typeof false
typeof [1, 2, 3, 4]
typeof {name:'John', age:34}
typeof new Date()
typeof function () {}
typeof myCar
typeof null
Try it Yourself »
Note
You cannot use typeof to define if a JavaScript object is an array or a date.
Both array and date return object as type.
See Also:
Browser Support
typeof
is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |