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.