This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

  • 2.6 JS Assignment

    Assignment operators assign values to JavaScript variables.

    Operator Example Same As
    = x = y 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
    |= x |= y x = x | y
    **= x **= y x = x ** y

    The **= operator is a part of ECMAScript 2016.

    Assignment Examples

    The = assignment operator assigns a value to a variable.

    Example 1: JavaScript assignment part 1
    var x = 10;

    The += assignment operator adds a value to a variable.

    Example 2: JavaScript assignment part 2
    var x = 10;
    x += 5;

    The -= assignment operator subtracts a value from a variable.

    Example 3: JavaScript assignment part 3
    var x = 10;
    x -= 5;

    The *= assignment operator multiplies a variable.

    Example 4: JavaScript assignment part 4
    var x = 10;
    x *= 5;

    The /= assignment divides a variable.

    Example 5: JavaScript assignment part 5
    var x = 10;
    x /= 5;

    The %= assignment operator assigns a remainder to a variable.

    Example 6 JavaScript assignment part 6
    var x = 10;
    x %= 5;
    Navigate this module

    Eventually the navigation links, above, will be replaced by these << (previous) and >> (next) buttons below.



    JavaScript icons used in the buttons provided by ICONS8.COM. Smartphone icons created by Freepik - Flaticon