ESLint
'use strict';
를 추가전역의 선두에 추가
'use strict';
function foo() {
x = 10; // Reference Error: x is not defined
}
foo();
함수 몸체의 선두에 추가
function foo() {
'use strict';
x = 10; // Reference Error: x is not defined
}
strict mode
를 적용하는 것은 피하자strict mode
를 적용하는 것은 피하자ReferenctError
가 발생 (function () {
'use strict';
x = 1;
console.log(x); // ReferenceError: x is undefined
}());
delete
연산자로 변수, 함수, 매개변수를 삭제하면 SyntaxError
가 발생(function () {
'use strict';
var x = 1;
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.
}
SyntaxError
가 발생this
this
에 undefined
가 바인딩(function () {
'use strict';
function foo() {
console.log(this); // undefined
}
foo();
function Foo() {
console.log(this); // Foo
}
new Foo();
}());
arguments
객체arguments
객체에 반영되지 않음(function (a) {
'use strict';
a = 2;
console.log(arguments); // { 0: 1, length: 1}
}(1));