Welcome to the Javascript Assignments Homepage, Guest!


Javascript | The assignment of values to variables




Assignment Operators

The equals sign, an assignment operator, will assign a value to a variable. var x = 1; Here we are declaring a variable named x, and assigning the value of 1 to the variable x. x += 4; Here we are adding 4 to the value of x, and reassigning the value for x to the new value which is 5. Next we will discuss many of the different ways to use the operators within Javascript.

  • Operator: =
    a = b;
    means a = b
    var x, y = 5;
    x = y;
    Current x: 5
  • Operator: = +=
    x += y;
    means x = x + y
    var x = 5;
    x += 5;
    Current x: 10
  • Operator: = -=
    a -= b;
    means a = a - b;
    var x = 5;
    x -= 5;
    Current x: 0
  • Operator: = *=
    x *= y;
    means x = x * y
    var x = 5;
    x *= 5;
    Current x: 25
  • Operator: = /=
    a /= b;
    means a = a / b
    var x = 5;
    x /= 5;
    Current x: 1
  • Operator: = %=
    x %= y;
    means x = x % y
    var x = 5;
    x %= 5;
    Current x: 0
  • Operator: = <<=
    a <<= b;
    means a = a << b
  • Operator: = >>=
    x >>= y;
    means x = x >> y
  • Operator: = >>>=
    a >>>= b;
    means a = a >>> b
  • Operator: = &=
    x <<= y;
    means x = x << y
  • Operator: ^=
    a ^= b;
    means a = a ^ b
  • Operator: |=
    x |= y;
    means x = x | y
  • Operator: **=
    a **= b;
    means a = a ** b [Experimental as of 2016; Suggested not to use due to instability]




Next, we will take a look at the different Data Types within Javascript.

Just follow the buttons to continue the tutorial, Guest