★ wanayoo — archive 1999 https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Assignment_OperatorsNouvelle recherche | Portail wanayoo
Your Search Results

    代入演算子

    概要

    代入演算子 (Assignment operator) は、右オペランドの値を左オペランドに代入します。

    演算子
    実装されたバージョン: JavaScript 1.0
    ECMA バージョン: ECMA-262

    基本となる代入演算子はイコール(=)で、右オペランドの値を左オペランドに代入します。たとえば x = y ならば y の値を x に代入します。他には通常の演算を短縮した代入演算子があり、以下の表に示します。

    短縮表記した演算子 意味
    x += y x = x + y
    x -= y x = x - y
    x *= y x = x * y
    x /= y x = x / y
    x %= y x = x % y
    x <<= y x = x << y
    x >>= y x = x >> y
    x >>>= y x = x >>> y
    x &= y x = x & y
    x ^= y x = x ^ y
    x |= y x = x | y

    上の表において、左列と右列とは全く同一というわけではないところが特徴です。代入演算子自身の左オペランドに別の代入演算子を含むとき、左オペランドは一度だけ評価されます。例を挙げます:

    a[i++] += 5 //i は1回だけ評価される
    a[i++] = a[i++] + 5 //i は2回評価される
    

    Document Tags and Contributors

    タグ:
    Contributors to this page: Potappo, ethertank, teoli
    最終更新者: teoli,