javascript환경에서 실수를 에러로 바꿔놓는다.
javascript 올바르지 않은 문법들을 사전에 검출할 수 있다.
(쓰기금지 프로퍼티의 정의, getter 전용 프로터피, 존재 하지 않는 프로퍼티, 존재하지 않는 변수, 존재하지 않는 객체에 대해 에러를 발생시킵니다.)
"use strict"
let v = "use strict example";
function strict(){
'use strict';
function online() {return "hi my name is bohun"}
}
'use strict'
x = 3 //index.js:3 Uncaught ReferenceError: x is not defined
'use strict'
x = 3
delete x //Delete of an unqualified identifier in strict mode
'use strict'
function code(x1 ,x1){}; //Duplicate parameter name not allowed in this context
'use strict'
let x = 010; //Octal literals are not allowed in strict mode.
"use strict";
var obj = {};
Object.defineProperty(obj, "x", {value:0, writable:false}); obj.x = 3.14;
//Cannot assign to read only property 'x' of object '#<Object>'
"use strict";
var obj = {get x() {return 0} }; obj.x = 3.14;
// TypeError: Cannot set property x of #<Object> which has only a getter
at index.js:2
"use strict";
let eval = 3.14;
let arguments = 3.14;
// Unexpected eval or arguments in strict mode
"use strict";
with (Math){x = cos(2)};
//Strict mode code may not include a with statement
"use strict";
eval ("var x = 2");
alert (x);
// x is not defined
자료 출처 :
1. https://www.w3schools.com/js/js_strict.asp
2.https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Strict_mode