This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Verify Github on Galxe. gid:E4aXLUWoLrbppJ5DUeVajG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo() { | |
return this; | |
} | |
// Non-Strict Mode | |
foo() === window; // true | |
foo.apply(undefined) === window; // true | |
// Strict Mode | |
foo() === undefined; // true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo() { | |
return this; | |
} | |
// Non-Strict Mode | |
foo.call(1) === 1; // false. | |
// Bởi foo.call(1) sẽ trả ra giá trị là một object, tương đương với `new Number(1)` | |
// Strict Mode | |
foo.call(1) === 1; // true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Non-Strict Mode | |
eval("var foo = 1"); | |
foo // 1 | |
// Strict Mode | |
"use strict"; | |
eval("var foo = 1"); | |
foo // Uncaught ReferenceError: foo is not defined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var foo = 1; | |
var bar = {foo: 2} | |
with (bar) { | |
console.log(foo); // Bạn sẽ gặp khó khăn trong việc xác định foo ở đây là biến, hay là thuộc tính của bar. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
function foo(bar, baz, bar) { // Uncaught SyntaxError: Duplicate parameter name not allowed in this context | |
} | |
foo(1, 2, 3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var foo = 1; | |
function bar() {}; | |
delete foo; // Uncaught SyntaxError: Delete of an unqualified identifier in Strict Mode. | |
delete bar; | |
var obj = {}; | |
Object.defineProperty(obj, "baz", { | |
value: 1, | |
configurable: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Without Strict Mode | |
NaN = "lol"; // Nothing happen | |
var obj = {}; | |
Object.defineProperty(obj, 'prop', {value: 1, writable:false}); | |
obj.prop; // => 2 | |
obj.prop = 10; | |
obj.prop; // => 2 | |
// With Strict Mode | |
"use strict"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Global variable | |
function foo() { | |
bar = 1; | |
} | |
foo(); | |
console.log(bar) // 1 | |
// Local variable | |
function foo() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo(){ | |
"use strict"; | |
// Uncaught ReferenceError: bar is not defined | |
bar = 0; | |
return bar; | |
} | |
// This will run normally | |
bar = 1; |
NewerOlder