While I was familiar with the concept of assert , I did not know that JavaScript had this functionality. Therefore, bearing in mind, I could be completely wrong, but it seems to me that this statement:
assert (foo.x || valueIfXIsNotDefined) === undefined;
... calls a function called assert() , passing it the parameter foo.x || valueIfXIsNotDefined foo.x || valueIfXIsNotDefined , and then comparing the return value with the assert() function with undefined . Perhaps you need the following:
assert(foo.x || valueIfXIsNotDefined === undefined);
If I try something like this with console.log() :
var foo = "", valueIfXIsNotDefined = "test"; console.log( foo.x === undefined); console.log(foo.x || valueIfXIsNotDefined === undefined);
Then it logs:
true false
Similarly, after:
var result = foo.x || valueIfXIsNotDefined;
result "test" .
http://jsfiddle.net/YBPyw/
Also, if you are really trying to set foo.x to something (where foo was a string), this will not work, so when you check foo.x later, it will give undefined .
source share