---
id: javascript-variables
title: "JavaScript Variables"
category: "Frontend"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["JS variables", "var let const", "identifiers", "assignment operator", "data containers"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.87
created_at: 2026-06-23
updated_at: 2026-06-23
review_reason: ""
merge_history: []
tags: ["javascript", "js", "web", "frontend", "w3schools", "variables", "var-let-const"]
raw_sources: ["https://www.w3schools.com/js/js_variables.asp"]
applied_in: []
github_commit: ""
---

# [[JavaScript Variables]]

## 🎯 한 줄 통찰 (One-line insight)
Variables are containers for storing data, declared in four ways (`var`, `let`, `const`, or automatically) — and the modern guidance is to prefer `const`, fall back to `let`, and avoid `var`. [S1]

## 🧠 핵심 개념 (Core concepts)
- **Variables are data containers** — they store data values. [S1]
- **Four ways to declare** — automatically, using `var`, using `let`, or using `const`. [S1]
- **Identifier rules** — names can contain letters, digits, underscores, and dollar signs; must begin with a letter, `$`, or `_`; are case-sensitive; reserved words cannot be used. [S1]
- **`$` is treated like a letter** — the dollar sign is treated as a letter in identifiers and is often used as an alias for the main function in JavaScript libraries; `_` is sometimes used to denote "private" variables. [S1]
- **Assignment vs equality** — the `=` operator assigns a value (it does not mean "equal to"). [S1]
- **`+` is overloaded** — with numbers it adds; with strings it concatenates. [S1]

## 🧩 추출된 패턴 (Extracted patterns)
- **const-first selection** — always declare with `const` if the value should not change (including new Arrays, Objects, Functions); use `let` when the value may change; avoid `var`. [S1]
- **One statement, many variables** — declare several variables in one statement, separated by commas, optionally across multiple lines. [S1]
- **String-vs-number `+` evaluation** — once a string appears in a `+` chain, subsequent operands are concatenated, so order and types matter. [S1]

## 📖 세부 내용 (Details)
**Variables = Data Containers** — Variables are containers for storing data (storing data values). [S1]

A variable can be declared four ways. Using `let`: [S1]
```javascript
let x = 5;
let y = 6;
let z = x + y;
```
Using `const`: [S1]
```javascript
const x = 5;
const y = 6;
const z = x + y;
```

**JavaScript Identifiers** — All JavaScript variables must be identified with unique names. These unique names are called identifiers. The general rules for constructing names for variables (unique identifiers) are: names can contain letters, digits, underscores, and dollar signs; names must begin with a letter, `$`, or `_`; names are case-sensitive (`y` and `Y` are different variables); and reserved words (like JavaScript keywords) cannot be used as names. [S1]

**JavaScript Underscore (`_`)** — Since JavaScript treats the underscore as a letter, identifiers containing `_` are valid variable names. Some programmers like to use underscores to denote "private (hidden)" variables. [S1]

**JavaScript Dollar Sign (`$`)** — Since JavaScript treats the dollar sign as a letter, identifiers containing `$` are valid variable names. Using the dollar sign is not very common in JavaScript, but professional programmers often use it as an alias for the main function in a JavaScript library. [S1]

**When to Use var, let, or const?** — The source's guidance: always declare variables; always use `const` if the value should not be changed; always use `const` if the type should not be changed (Arrays and Objects); only use `let` if you can't use `const`; only use `var` if you MUST support old browsers. [S1]

**One Statement, Many Variables** — You can declare many variables in one statement. Start the statement with `let` and separate the variables by comma: [S1]
```javascript
let person = "John Doe", carName = "Volvo", price = 200;
```
A declaration can span multiple lines: [S1]
```javascript
let person = "John Doe",
carName = "Volvo",
price = 200;
```

**The Assignment Operator** — In JavaScript, the `=` sign is an "assignment" operator, not an "equal to" operator. [S1]

**JavaScript Arithmetic** — You can do arithmetic with JavaScript variables, using operators like `=` and `+`. The value of `x` differs depending on whether operands are numbers or strings: [S1]
```javascript
let x = 5 + 2 + 3;
```
```javascript
let x = "John" + " " + "Doe";
```
If you put a number in quotes, the rest of the numbers will be treated as strings and concatenated: [S1]
```javascript
let x = "5" + 2 + 3;
```
```javascript
let x = 2 + 3 + "5";
```

## 🛠️ 적용 사례 (Applied in summary)
The page's own snippets are the canonical applied examples — `let`/`const` declarations computing `x + y`, the comma-separated multi-variable statement, and the `+` arithmetic vs concatenation cases. No external project/commit applications found in the source.

## 💻 코드 패턴 (Code patterns)
Declare and compute:
```javascript
let x = 5;
let y = 6;
let z = x + y;
```
Many variables, one statement:
```javascript
let person = "John Doe", carName = "Volvo", price = 200;
```

## ⚖️ 비교 및 선택 기준 (Comparison & decision criteria)
The source gives explicit selection rules among the declaration keywords: [S1]

| Keyword | Use when |
|---------|----------|
| `const` | The value (or type, for Arrays/Objects) should not change — the default choice |
| `let` | You cannot use `const` because the value will change |
| `var` | Only if you MUST support old browsers |

## ⚖️ 모순 및 업데이트 (Contradictions & updates)
No contradictions found in the source. (The page notes `var` was the only option before 2015 (ES6) but is now discouraged — an update in guidance, not a contradiction.)

## ✅ 검증 상태 및 신뢰도
- **상태:** draft
- **검증 단계:** conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
- **신뢰 점수:** 0.87
- **중복 검사 결과:** 신규 생성 (New discovery)

## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[JavaScript Tutorial]]
- **관련 개념:** [[JavaScript Let]], [[JavaScript Const]], [[JavaScript Syntax]]
- **참조 맥락:** The foundation for all data handling; refined by the dedicated Let and Const pages.

## 📚 출처 (Sources)
- [S1] W3Schools — JavaScript Variables — https://www.w3schools.com/js/js_variables.asp

## 📝 변경 이력 (Change history)
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Variables" page (Astra wiki-curation, P-Reinforce v3.1 format).
