NOTE: As per ECMAScript5.1, section 15.1.1.3, window.undefined is read-only.
- Modern browsers implement this correctly. for example: Safari 5.1, Firefox 7, Chrome 20, etc.
- Undefined is still changeable in: Chrome 14, ...
When I recently integrated Facebook Connect with Tersus, I initially received the error messages Invalid Enumeration Value and Handler already exists when trying to call Facebook API functions.
It turned out that the cause of the problem was
object.x === undefined
returning false when there is no property 'x' in 'object'.
I worked around the problem by replacing strict equality with regular equality in two Facebook functions:
FB.Sys.isUndefined = function(o) { return o == undefined;};
FB.Sys.containsKey = function(d, key) { return d[key] != undefined;};
This made things work for me, but seems to hint at some sort of collision between Facebook's JavaScript code and my own.
What could cause this?
Hint: It is well documented that undefined == null while undefined !== null. This is not the issue here. The question is how comes we get undefined !== undefined.
var a = {}; a.b === undefined //true. Are you sure yourobject.x === undefinedreturning false was because there was no field x in object?undefinedglobally, and everything would break :(window.undefinedbeing read-only,void(0)was considered the standard extra-safe way to get your hands on the undefined value if you didn't want to trust you're environment'sundefinedvariable. MDN