I have written a simple function that nullifies itself after its first call:
var nullify = function(){
nullify = null;
return 1;
};
If I call it two times, like this:
console.log(nullify());
console.log(nullify);
Then the 1st expression will return 1
, and the other will evaluate to null
. All clear up to this point.
If I however do it in a single expression and wrap it in a function:
var fun = function(f){
return f() && !f;
}
Then, for some reason:
console.log(fun(nullify));
evaluates to false
, while I would expect it to be true
, since 1st operand will return 1
and the other, as a negation of null
, true
.
The evaluation of the right-hand operand occurs when the nullify
functiion has already called nullify = null
, is that right? What am I missing?