typeof null 1

In ES5 typeof null evaluates to 'object'. This quirk was one of the changes we wanted to fix in ES5 but at the time we agreed that we did not want any semantic changes. With Harmony there will be a way to opt in (TBD) so when you opt in we can now provide a better value for typeof null.


typeof null  // 'null'

In V8 with the Harmony flag turned on this changes all the typeof expressions so beware and please update your JS libraries to be future compatible to handle this correctly. Something along the following lines should make your code work both in ES5 and in future versions of ES:


switch (typeof expression) {
  case 'boolean':
    ...
    break;
  case 'function':
    ...
    break;
  case 'number':
    ...
    break;
  case 'string':
    ...
    break;
  case 'undefined':
    ...
    break;
  default:  // object or null
    var isNull = expression === null;
    ...
}

// Bad, because it included null in old ES versions
typeof object === 'object'

// Good
object === null