docs(10_Wiki): W3Schools 위키화 — HTML/CSS/JavaScript(core)
W3Schools 튜토리얼을 P-Reinforce v3.1 포맷으로 위키화(영어 본문, 한/영 섹션 헤더). - Topic_HTML: 59문서 (튜토리얼+예제, 레퍼런스/메타 제외) - Topic_CSS: 190문서 (메인 + Advanced/Flexbox/Grid/RWD 전체) - Topic_JavaScript: 120문서 (코어 언어; Temporal/DOM상세/BOM/WebAPI/AJAX/jQuery/Graphics 등은 후속) 각 폴더 00_INDEX.md(MOC) 포함. 코드 verbatim, 미확인분은 "Not found in source" 표기. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
---
|
||||
id: javascript-strict-mode
|
||||
title: "JavaScript Strict Mode"
|
||||
category: "Frontend"
|
||||
status: "draft"
|
||||
verification_status: "conceptual"
|
||||
canonical_id: ""
|
||||
aliases: ["use strict", "strict mode", "ECMAScript 5 strict", "strict directive", "JS strict"]
|
||||
duplicate_of: ""
|
||||
source_trust_level: "B"
|
||||
confidence_score: 0.88
|
||||
created_at: 2026-06-23
|
||||
updated_at: 2026-06-23
|
||||
review_reason: ""
|
||||
merge_history: []
|
||||
tags: ["javascript", "js", "web", "frontend", "w3schools", "strict-mode", "use-strict", "es5"]
|
||||
raw_sources: ["https://www.w3schools.com/js/js_strict.asp"]
|
||||
applied_in: []
|
||||
github_commit: ""
|
||||
---
|
||||
|
||||
# [[JavaScript Strict Mode]]
|
||||
|
||||
## 🎯 한 줄 통찰 (One-line insight)
|
||||
`"use strict";` (ECMAScript 5) makes JavaScript run in strict mode, turning previously-tolerated "bad syntax" into real errors. [S1]
|
||||
|
||||
## 🧠 핵심 개념 (Core concepts)
|
||||
- **`"use strict"` is a directive** — it is a literal expression, ignored by older JavaScript versions, that tells the engine to execute code in strict mode. [S1]
|
||||
- **Introduced in ES5** — strict mode was added in ECMAScript 5. [S1]
|
||||
- **Two scopes** — declared at the top of a script it applies globally; declared at the top of a function it applies only inside that function. [S1]
|
||||
- **Must appear at the beginning** — the directive must be at the start of the script or function to be recognized. [S1]
|
||||
- **Turns mistakes into errors** — strict mode makes it easier to write secure code by converting silent bad syntax into thrown errors (e.g. prevents accidental globals). [S1]
|
||||
|
||||
## 🧩 추출된 패턴 (Extracted patterns)
|
||||
- **Opt into safety per file or per function** — place `"use strict";` at the top of a script (global) or a function (local). [S1]
|
||||
- **Declare before use** — strict mode forbids using undeclared variables/objects, forcing explicit declarations. [S1]
|
||||
- **Avoid deprecated/unsafe constructs** — `with`, octal literals, duplicate parameters, deleting variables, etc. are all disallowed. [S1]
|
||||
|
||||
## 📖 세부 내용 (Details)
|
||||
**Declaring strict mode**
|
||||
Strict mode is declared by adding `"use strict";` to the beginning of a script or a function. Declared at the beginning of a script, it has global scope (all code in the script executes in strict mode): [S1]
|
||||
```javascript
|
||||
"use strict";
|
||||
x = 3.14; // This will cause an error because x is not declared
|
||||
```
|
||||
Declared inside a function, it has local scope (only the code inside the function is in strict mode): [S1]
|
||||
```javascript
|
||||
"use strict";
|
||||
myFunction();
|
||||
|
||||
function myFunction() {
|
||||
y = 3.14; // This will cause an error
|
||||
}
|
||||
```
|
||||
|
||||
**Why strict mode?**
|
||||
Strict mode makes it easier to write "secure" JavaScript. It changes previously accepted "bad syntax" into real errors. For example, in normal JavaScript, mistyping a variable name creates a new global variable; in strict mode this throws an error, so you cannot accidentally create a global variable. [S1]
|
||||
|
||||
**Not allowed in strict mode**
|
||||
|
||||
Using a variable (or object) without declaring it: [S1]
|
||||
```javascript
|
||||
"use strict";
|
||||
x = 3.14; // This will cause an error
|
||||
```
|
||||
```javascript
|
||||
"use strict";
|
||||
x = {p1:10, p2:20}; // This will cause an error
|
||||
```
|
||||
|
||||
Deleting a variable (or object) or a function is not allowed: [S1]
|
||||
```javascript
|
||||
"use strict";
|
||||
let x = 3.14;
|
||||
delete x; // This will cause an error
|
||||
```
|
||||
```javascript
|
||||
"use strict";
|
||||
function x(p1, p2) {};
|
||||
delete x; // This will cause an error
|
||||
```
|
||||
|
||||
Duplicating a parameter name is not allowed: [S1]
|
||||
```javascript
|
||||
"use strict";
|
||||
function x(p1, p1) {}; // This will cause an error
|
||||
```
|
||||
|
||||
Octal numeric literals and octal escape characters are not allowed: [S1]
|
||||
```javascript
|
||||
"use strict";
|
||||
let x = 010; // This will cause an error
|
||||
```
|
||||
```javascript
|
||||
"use strict";
|
||||
let x = "\010"; // This will cause an error
|
||||
```
|
||||
|
||||
Writing to a read-only property is not allowed: [S1]
|
||||
```javascript
|
||||
"use strict";
|
||||
const obj = {};
|
||||
Object.defineProperty(obj, "x", {value:0, writable:false});
|
||||
obj.x = 3.14; // This will cause an error
|
||||
```
|
||||
|
||||
Writing to a get-only property is not allowed: [S1]
|
||||
```javascript
|
||||
"use strict";
|
||||
const obj = {get x() {return 0} };
|
||||
obj.x = 3.14; // This will cause an error
|
||||
```
|
||||
|
||||
Deleting an undeletable property is not allowed: [S1]
|
||||
```javascript
|
||||
"use strict";
|
||||
delete Object.prototype; // This will cause an error
|
||||
```
|
||||
|
||||
The word `eval` cannot be used as a variable: [S1]
|
||||
```javascript
|
||||
"use strict";
|
||||
let eval = 3.14; // This will cause an error
|
||||
```
|
||||
|
||||
The word `arguments` cannot be used as a variable: [S1]
|
||||
```javascript
|
||||
"use strict";
|
||||
let arguments = 3.14; // This will cause an error
|
||||
```
|
||||
|
||||
The `with` statement is not allowed: [S1]
|
||||
```javascript
|
||||
"use strict";
|
||||
with (Math){x = cos(2)}; // This will cause an error
|
||||
```
|
||||
|
||||
For security reasons, `eval()` is not allowed to create variables in the scope from which it was called: [S1]
|
||||
```javascript
|
||||
"use strict";
|
||||
eval ("var x = 2");
|
||||
alert (x); // This will cause an error
|
||||
```
|
||||
|
||||
**The "use strict" directive**
|
||||
The `"use strict"` directive is only recognized at the beginning of a script or a function. [S1]
|
||||
|
||||
## 🛠️ 적용 사례 (Applied in summary)
|
||||
The page's snippets are the applied cases: each shows a construct that runs silently (or wrongly) in normal mode but throws under `"use strict";` — undeclared assignment, `delete` on variables/functions, duplicate parameters, octal literals, read-only/get-only writes, reserved words `eval`/`arguments`, `with`, and `eval()` scope injection. No external project/commit applications found in the source.
|
||||
|
||||
## 💻 코드 패턴 (Code patterns)
|
||||
Enable strict mode globally (top of script) (language: JavaScript):
|
||||
```javascript
|
||||
"use strict";
|
||||
x = 3.14; // Error: x is not declared
|
||||
```
|
||||
Enable strict mode for a single function:
|
||||
```javascript
|
||||
function myFunction() {
|
||||
"use strict";
|
||||
// strict-mode code here
|
||||
}
|
||||
```
|
||||
|
||||
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
|
||||
No contradictions found in the source. The page notes that older browsers/JavaScript versions simply ignore the `"use strict";` string, so it is backward-compatible.
|
||||
|
||||
## ✅ 검증 상태 및 신뢰도
|
||||
- **상태:** draft
|
||||
- **검증 단계:** conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
|
||||
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
|
||||
- **신뢰 점수:** 0.88
|
||||
- **중복 검사 결과:** 신규 생성 (New discovery)
|
||||
|
||||
## 🔗 지식 그래프 (Knowledge Graph)
|
||||
- **상위/루트:** [[JavaScript Tutorial]]
|
||||
- **관련 개념:** [[JavaScript Scope]], [[JavaScript Hoisting]], [[JavaScript var let const]], [[JavaScript Best Practices]]
|
||||
- **참조 맥락:** Referenced when hardening JavaScript against silent errors and accidental globals.
|
||||
|
||||
## 📚 출처 (Sources)
|
||||
- [S1] W3Schools — JavaScript Strict Mode — https://www.w3schools.com/js/js_strict.asp
|
||||
|
||||
## 📝 변경 이력 (Change history)
|
||||
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Strict Mode" page (Astra wiki-curation, P-Reinforce v3.1 format).
|
||||
Reference in New Issue
Block a user