JavaScript: typeof

JavaScript: typeof

  • 2020-5-14

As to typeof operator, we need to keep three 4 in ming:

  1. It returns a string ('undefined', 'object', 'boolean', 'number', 'bigint', 'string', 'symbol' and 'function')
  2. typeof null === 'object' (a never fixed bug, see here)
  3. typeof NaN === 'number' (even if NaN is "not a number", Use Number.isNaN to test NaN instead)
  4. typeof [] === 'object' (Use Array.isArray to test array instead)