Understanding 'undefined'

by sikusikucom

JavaScript

var x = 10;
console.log(x);  // 10

// Any reference to 'y' will throw an error at this point.
//   e.g. 'if (y) ...', 'if (y === undefined) ...'
var y;
console.log(y);  // undefined
console.log(
    y === undefined,  // true
    y === null        // false
);

// Any reference to 'z' will throw an error at this point.
//   e.g. 'console.log(z)'
var z = undefined;
console.log(
    z === undefined  // true       
);