"use strict";이렇게 맨 위에 써서
자바스크립트를 더 엄격한 규칙으로 실행하게 만드는 기능❗
이걸 쓰면 실수로 잘못 쓴 코드를 더 잘 잡아줌
에러 없이 지나가던 잘못된 코드도 에러를 내서 경고⚠
"use strict"; // 이 줄이 제일 위에 와야 함!
x = 10; // ❌ 에러! 변수 선언 안 했다고 바로 막아줘
console.log(x);
x = 10; // 변수 선언 안 했는데도 실행됨
console.log(x); // 👉 10 출력됨

let greeting = 'hello';
greating = 'hi'; // 오타 냄
console.log(greeting);




'use strict';
// ✅ strict mode 켜기! 실수나 위험한 코딩을 에러로 잡아줌
const obj = {};
// ✅ 빈 객체(obj)를 하나 만듦
Object.defineProperty(obj, "readOnly", {
writable: false, // ✅ 이 속성은 수정할 수 없게 설정함 (읽기 전용)
value: 7 // ✅ "readOnly"라는 속성의 값은 7로 설정함
});
// ✅ 즉, obj.readOnly = 7인데, 수정은 못하게 막아둠
console.log(obj);
// ✅ { readOnly: 7 } 출력됨
obj.readOnly = 10;
// ❌ 에러는 안 나지만 값은 바뀌지 않음 (strict 모드니까 무시되지 않고 막힘)
console.log(obj);
// ✅ 여전히 { readOnly: 7 } 출력됨 — 값 안 바뀜!

'use strict'
function add(a, a, b) {
return a + a + b;
}
console.log(add(1, 2, 3));

"string".prop = 7;
console.log("string".prop); // undefined 출력
'use strict'
"string".prop = 7;
console.log("string".prop); // undefined 출력

function sum(a, b) {
console.log(this);
return a + b;
}
console.log(this);
sum(1, 2);



'use strict';
function sum(a, b) {
console.log(this); // 👉 window가 되게 하고 싶다!
return a + b;
}
// 이때 this는 전역에서 window니까, 고정됨!
sum.bind(this)(1, 2);
함수의
this를 원하는 값으로 "고정"해서
새로운 함수로 만들어주는 메서드😎
- 기본 모드에선 그냥 함수 호출 시
this가 자동으로window가 됨"use strict"모드에선 실수를 막기 위해
👉 함수에서 그냥 호출하면this를window가 아닌undefined로 바꿈
bind(this)
➡ 함수 안의this를 외부의this(=window)로 고정📌- 엄격 모드라도
this를 명시적으로 줬으니
→undefined가 아니라window