Skip to content

变量

一句话解释

变量是 named 容器 for 存储数据那个能 更改虽然你的 program 运行.

用大白话说

Think 的变量 as labeled box 哪里你 存储信息. 你编写 name on box (如 age) 所以你 能查找它 later, and 你 put 值内部 (如 25). Whenever you need that value, you just refer to the box by its name.

The key word is "变量" — the value inside can change. You might start with age = 25 and later update it to age = 26. The name stays the same, but the contents can be replaced at any time during your program.

Variables are the most fundamental building block of programming. Almost every program uses them to keep track of user input, calculation results, counters, and much more. Without variables, your program would have no way to remember anything.

示例

javascript
let age = 25;
console.log(age); // 25

age = 26;
console.log(age); // 26

age 是变量. 我们首先存储 25 in 它, 然后更新它 到 26. name age stays 相同.

工作原理

  1. Declare 变量使用 name (e.g. let age).
  2. Assign a value to it (e.g. age = 25).
  3. Use the variable by its name — the program reads the current value.
  4. Reassign any time (e.g. age = 26) — the old value is replaced.

常见混淆

  • 容易混淆的对象: 常量

    关键区别: 变量能 是 reassigned 到新 值之后它 是创建; 常量 cannot 更改一次它 是设置.

相关术语

相关资源

相关课程

  • 变量

    学习如何变量工作 in programming

相关练习

相关项目

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表