This coffeescript...
if x? isnt '' then console.log x
Compiles to this javascript...
if ((typeof x !== "undefined" && x !== null) !== '') {
console.log(x);
}
Where typeof x
is checked against undefined
However, if I use x
in the current scope, coffeescript explicitly declares it at the to of the scope, and then does not bother checking for undefined
...
This coffeescript...
x = y.z
if x? isnt '' then console.log x
Compiles to this javascript...
var x;
x = y.z;
if ((x != null) !== '') {
console.log(x);
}
It is possible that x
ends up being undefined
if y.z
is undefined
. Why does coffeescript not feel the need to check for undefined in the if statement?