变量
一句话解释
变量 是 named 容器 for 存储 值 那个 能 是 referenced and 更改 later.
用大白话说
变量是 labeled box 那个持有值. 你 give 它 name, 存储某事 in 它, and later 读取 or 更改什么's 内部. In JavaScript, 你 declare 变量使用 let (changeable), const (unchangeable binding), or var (older, function-scoped).
Variables are how programs remember things. Without variables, every value would be anonymous and temporary. With variables, you can store user input, track game scores, hold API responses, and build up complex data structures.
Choose const by default — it prevents accidental reassignment. Use let when you know the value will change. Avoid var in modern code because its function-scoping and hoisting behavior can cause subtle bugs.
示例
let score = 0;
score = score + 10;
const playerName = "Ada";
console.log(playerName, score); // "Ada" 10score 是 declared 使用 let and reassigned. playerName 是 declared 使用 const and cannot 是 reassigned.
常见混淆
容易混淆的对象: 常量
关键区别: 变量 (let) 能 是 reassigned; 常量 (const) cannot 是 reassigned, 虽然 如果 它 持有 对象, 对象's 属性 能 still 更改.
相关术语
相关资源
相关课程
- 变量
学习 关于 变量 declaration.
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。