Movatterモバイル変換


[0]ホーム

URL:


  1. 面向开发者的 Web 技术
  2. JavaScript
  3. JavaScript 参考
  4. 表达式和运算符
  5. 赋值(=)

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in EnglishAlways switch to English

赋值(=)

Baseline Widely available

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: 2console.log((x = y + 1)); // 3 + 1// Expected output: 4console.log((x = x * y)); // 4 * 3// Expected output: 12

语法

js
x = y

示例

简单赋值和链式赋值

js
// 假设已经存在以下变量//  x = 5//  y = 10//  z = 25x = y; // x 为 10x = y = z; // x, y 都为 25

规范

Specification
ECMAScript® 2026 Language Specification
# sec-assignment-operators

浏览器兼容性

参见

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp