"use strict";

// strict mode가 적용될 코드
"use strict";

function exampleFunction() {
    nonDeclaredVar = 10; // ReferenceError: nonDeclaredVar is not defined
}

exampleFunction();
"use strict"

// 엄격 모드가 여기서부터 적용됩니다.
'use strict';

// 엄격 모드가 이 파일 전체에 적용됩니다.
function myFunction() {
    "use strict";
    
    // 엄격 모드가 이 함수 내에만 적용됩니다.
}
function myStrictFunction() {
    // 모듈이기 때문에 기본적으로 엄격 모드가 적용됩니다.
}

export default myStrictFunction;
"use strict"

function exampleStrict() {
    strictVar = 10; // ReferenceError: strictVar is not defined
}

exampleStrict();
function exampleNonStrict() {
    nonStrictVar = 20; // No error, 암묵적으로 전역 변수로 처리
}

exampleNonStrict();
console.log(nonStrictVar); // 20

"use strict"

const sealedObject = Object.seal({ prop: 10 });

// 엄격 모드에서는 확장 불가능한 객체에 속성 값을 할당하려고 하면 에러가 발생합니다.
sealedObject.newProp = 20; // TypeError: Cannot add property newProp, object is not extensible
const nonStrictSealedObject = Object.seal({ prop: 10 });

// 엄격 모드가 아니라면 확장 불가능한 객체에 값 할당 시 에러가 발생하지 않습니다.
nonStrictSealedObject.newProp = 20; // No error, 새로운 속성이 객체에 추가
"use strict"

function strictExample(param1, param1) {
    console.log(param1);
}

strictExample(10, 20); // SyntaxError: Duplicate parameter name not allowed in this context
function nonStrictExample(param1, param1) {
    console.log(param1);
}

nonStrictExample(10, 20); // 20 (두 번째 매개변수의 값)
"use strict"

function strictFunction() {
    return this;
}

console.log(strictFunction()); // undefined
function nonStrictFunction() {
    return this;
}

console.log(nonStrictFunction()); // 전역 객체 (브라우저에서는 window)
"use strict"

// 엄격 모드를 적용하지 않은 경우
var globalVar = 10;

function someFunction(x) {
    y = x * 2; // 오류 발생 가능
    return y;
}

// 엄격 모드를 적용한 경우
var globalVar = 10;

function someFunction(x) {
    var y = x * 2; // 변수 명시적 선언
    return y;
}
엄격 모드의 브라우저 호환성
지시어
데스크탑 Chrome
Chrome
데스크탑데스크탑 Edge
Edge
데스크탑 Firefox
Firefox
Safari
Safari
"use strict" 13 10 4 6

caniuse.com에서 더 자세한 정보를 확인해 보세요.