The behavior you experience is related to the fact that the undefined property of the Global object is changed to any implementation based on ECMAScript 3. (recent versions of Chrome use ES5, but this behavior is still present).
Consider the second fragment:
var x = window.foo; window[x] = null; alert( window.bar === undefined );
The variable x will contain the value undefined , since the foo property does not exist.
By setting window[x] = null , you override the value of the undefined property:
window[x] = null; // is equivalent to window['undefined'] = null; // or window.undefined = null; //
(In your first snippet, when you assign window.x = null , you create a property named "x" on the window object.)
Therefore (in the second fragment), the undefined property will contain null , and window.bar will window.bar undefined :
alert( window.bar === undefined ); // false alert( undefined === null ); // false
The undefined property is not specified as { ReadOnly } in ECMAScript 3 (with its friends NaN , Infinity ).
This has changed in ECMAScript 5, these properties are described as non-writable.
source share