ä¹ç®ä»£å ¥æ¼ç®å (*=)
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æ.
ä¹ç®ä»£å
¥æ¼ç®å (*=) ã¯ã2 ã¤ã®ãªãã©ã³ãã§ä¹ç®ãè¡ããçµæãå·¦ãªãã©ã³ãã«ä»£å
¥ãã¾ãã
試ãã¦ã¿ã¾ããã
let a = 2;
console.log((a *= 3));
// äºæ³ãããçµæ: 6
console.log((a *= "hello"));
// äºæ³ãããçµæ: NaN
æ§æ
js
x *= y
解説
x *= y 㯠x = x * y ã¨åçã§ãããå¼ x ãä¸åº¦ã ãè©ä¾¡ãããç¹ãç°ãªãã¾ãã
ä¾
>æ°å¤ã使ç¨ããä¹ç®ä»£å ¥
js
let bar = 5;
bar *= 2; // 10
ãã®ä»ã®é·æ´æ°ä»¥å¤ã®å¤ã¯æ°å¤ã«å¤æããã¾ãã
js
let bar = 5;
bar *= "foo"; // NaN
é·æ´æ°ã使ç¨ããä¹ç®ä»£å ¥
js
let foo = 3n;
foo *= 2n; // 6n
foo *= 1; // TypeError: Cannot mix BigInt and other types, use explicit conversions
仿§æ¸
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-assignment-operators> |