[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/pagers-org/JavaScriptCrash/main/Javascript/strict_mode.md [Back]  [Original]

ES5 . . (strict) . ## strict mode > . . ? var , , (Implict global) . . - : . ```js function foo() { x = 10; } foo(); console.log(x); // 10 ``` - 1. foo x 10 . 2. x . 3. foo , x . 4. ReferenceError x . 5. x . ** **. ES5 strict mode( ) , ESLint .
## strict mode > `'use strict';` . - . ```js 'use strict'; function foo(){ x = 10; // ReferenceError: x is not defined } foo(); ``` - . ```js function foo(){ 'use strict'; x = 10; // ReferenceError: x is not defined } foo(); ``` - . ```js function foo(){ x = 10; 'use strict'; } foo(); ```
## ### > strict mode . - . ```html Document ``` - . .
### > strict mode, non-strict mode? , strict mode . - strict mode strict mode . ```js (function(){ var x = 10; function foo(){ 'use strict'; x = 20; } foo(); }()); ``` - ` ? ...` strict mode ?
## strict mode > , // , , with . ### > ReferenceError . ```js (function(){ 'use strict'; x = 10; console.log(x); // ReferenceError: x is not defined }()); ```
### // > delete SyntaxError . ```js (function(){ 'use strict'; var x = 10; delete x; // SyntaxError: Delete of an unqualified identifier in strict mode. function foo(a) { delete a; // SyntaxError: Delete of an unqualified identifier in strict mode. } delete foo; // SyntaxError: Delete of an unqualified identifier in strict mode. }()); ```
### > SytaxError . ```js (function(){ 'use strict'; function foo(a, a) { return a + a; // SyntaxError: Duplicate parameter name not allowed in this context } console.log(foo(1, 2)); }()); ```
### with > with SyntaxError . ```js (function(){ 'use strict'; with({ x: 1 }){ console.log(x); // SyntaxError: Strict mode code may not include a with statement } }()); ``` ! strict mode ? ``, .
## strict mode > this arguments . ### this > this undefined . this . ```js (function(){ 'use strict'; function foo(){ console.log(this); // undefined } foo(); function Foo(){ console.log(this); // Foo } new Foo(); }()); ```
### arguments > . ```js (function(x){ 'use strict'; x = 10; console.log(arguments); // Arguments[callee: (...), Symbol(Symbol.iterator): ] }()); ```


Web Proxy Viewer  |  New URL  |  Original Page