Skip to main content
Commonmark migration
Source Link

#ES5+ (Javascript)#

ES5+ (Javascript)

EDIT: Removed explicit variable declaration, as otherwise it was hoisted and a non-configurable window.x property was created (unless run line by line in the REPL console).

Explanation:

Makes advantage of the fact that any globally scoped variable is also a property of the window object, and redefines "window.x" property to have a constant value of 1.

Clean

for(x=0; x<8; x+=1) console.log(x);

Augmented

Object.defineProperty(window,'x',{value:1});
for(x=0; x<8; x+=1) console.log(x);

NOTE: To make this work in Node.js, just replace "window" with "global" (tested in Node.js 6.8.0)

#ES5+ (Javascript)#

EDIT: Removed explicit variable declaration, as otherwise it was hoisted and a non-configurable window.x property was created (unless run line by line in the REPL console).

Explanation:

Makes advantage of the fact that any globally scoped variable is also a property of the window object, and redefines "window.x" property to have a constant value of 1.

Clean

for(x=0; x<8; x+=1) console.log(x);

Augmented

Object.defineProperty(window,'x',{value:1});
for(x=0; x<8; x+=1) console.log(x);

NOTE: To make this work in Node.js, just replace "window" with "global" (tested in Node.js 6.8.0)

ES5+ (Javascript)

EDIT: Removed explicit variable declaration, as otherwise it was hoisted and a non-configurable window.x property was created (unless run line by line in the REPL console).

Explanation:

Makes advantage of the fact that any globally scoped variable is also a property of the window object, and redefines "window.x" property to have a constant value of 1.

Clean

for(x=0; x<8; x+=1) console.log(x);

Augmented

Object.defineProperty(window,'x',{value:1});
for(x=0; x<8; x+=1) console.log(x);

NOTE: To make this work in Node.js, just replace "window" with "global" (tested in Node.js 6.8.0)

added 44 characters in body
Source Link
zeppelin
  • 8.5k
  • 3
  • 21
  • 42

#ES5+ (Javascript)#

EDIT: Removed explicit variable declaration, as otherwise it was hoisted and a non-configurable window.x property was created (unless run line by line in the REPL console).

Explanation:

Makes advantage of the fact that any globally scoped variable is also a property of the window object, and redefines "window.x" property to have a constant value of 1.

Note that despite var is inside the for() declaration block, it still refers to a globally scoped x (due to hoisting).

Clean

for(var x=0; x<8; x+=1) console.log(x);

Augmented

Object.defineProperty(window,'x',{value:1});
for(var x=0; x<8; x+=1) console.log(x);

NOTE: To make this work in Node.js, just replace "window" with "global" (tested in Node.js 6.8.0)

#ES5+ (Javascript)#

Explanation:

Makes advantage of the fact that any globally scoped variable is also a property of the window object, and redefines "window.x" property to have a constant value of 1.

Note that despite var is inside the for() declaration block, it still refers to a globally scoped x (due to hoisting).

Clean

for(var x=0; x<8; x+=1) console.log(x);

Augmented

Object.defineProperty(window,'x',{value:1});
for(var x=0; x<8; x+=1) console.log(x);

#ES5+ (Javascript)#

EDIT: Removed explicit variable declaration, as otherwise it was hoisted and a non-configurable window.x property was created (unless run line by line in the REPL console).

Explanation:

Makes advantage of the fact that any globally scoped variable is also a property of the window object, and redefines "window.x" property to have a constant value of 1.

Clean

for(x=0; x<8; x+=1) console.log(x);

Augmented

Object.defineProperty(window,'x',{value:1});
for(x=0; x<8; x+=1) console.log(x);

NOTE: To make this work in Node.js, just replace "window" with "global" (tested in Node.js 6.8.0)

added 1 character in body
Source Link
zeppelin
  • 8.5k
  • 3
  • 21
  • 42

#ES6#ES5+ (Javascript)#

Explanation:

Makes advantage of the fact that any globally scoped variable is also a property of the window object, and redefines "window.x" property to have a constant value of 1.

Note that despite var is inside the for() declaration block, it still refers to a globally scoped x (due to hoisting).

Clean

for(var x=0; x<8; x+=1) console.log(x);

Augmented

Object.defineProperty(window,'x',{value:1});
for(var x=0; x<8; x+=1) console.log(x);

#ES6 (Javascript)#

Explanation:

Makes advantage of the fact that any globally scoped variable is also a property of the window object, and redefines "window.x" property to have a constant value of 1.

Note that despite var is inside the for() declaration block, it still refers to a globally scoped x (due to hoisting).

Clean

for(var x=0; x<8; x+=1) console.log(x);

Augmented

Object.defineProperty(window,'x',{value:1});
for(var x=0; x<8; x+=1) console.log(x);

#ES5+ (Javascript)#

Explanation:

Makes advantage of the fact that any globally scoped variable is also a property of the window object, and redefines "window.x" property to have a constant value of 1.

Note that despite var is inside the for() declaration block, it still refers to a globally scoped x (due to hoisting).

Clean

for(var x=0; x<8; x+=1) console.log(x);

Augmented

Object.defineProperty(window,'x',{value:1});
for(var x=0; x<8; x+=1) console.log(x);
minor text style changes
Source Link
zeppelin
  • 8.5k
  • 3
  • 21
  • 42
Loading
Source Link
zeppelin
  • 8.5k
  • 3
  • 21
  • 42
Loading