HTML: Markup language
CSS: Styling language
JavaScript: Scripting language
Web APIs: Programming interfaces
All web technology
Learn web development
Discover our tools
Get to know MDN better
此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。
View in English Always switch to English
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
简单赋值运算符(=)用于给变量赋值。赋值表达式本身的值为要赋值的值。为了将一个值赋给多个变量,可以链式使用赋值运算符。
=
let x = 2; const y = 3; console.log(x); // Expected output: 2 console.log((x = y + 1)); // 3 + 1 // Expected output: 4 console.log((x = x * y)); // 4 * 3 // Expected output: 12
x = y
// 假设已经存在以下变量 // x = 5 // y = 10 // z = 25 x = y; // x 为 10 x = y = z; // x, y 都为 25
Enable JavaScript to view this browser compatibility table.