Javascript
100 Front End Interview Questions Challenge

Typeof

Mute
Current Time 0:00
/
Duration Time 0:00
Loaded: 0%
Progress: 0%
Stream TypeLIVE
Remaining Time -0:00
 
PRO

The typeof operator returns the data type of the parameter, but it has various 'gotchas'.

Things to be aware of:

  • typeof recognizes NaN as a number.
  • typeof recognizes any complex data types, like Arrays or Maps, as simply object.
  • typeof also recognizes null as an object.
  • There are better ways to determine the types of complex data objects. For arrays, you can call Array.isArray(object) method. Other data types have similar methods for determining type.
 

I finished! On to the next chapter