Page 339 - Webapplication11_C11_Flipbook
P. 339
Output of the code is as follows:
Notes
The difference between ‘/’ and ‘%’ operators is that ‘/’ operator gives the quotient and ‘%’ operator gives the
remainder obtained during division.
Assignment Operators
Assignment operators are used to assign the value of the right-hand operand to the left-hand operand. JavaScript
has only one assignment operator (=). Some other assignment operators are created by combining the assignment
operator with an arithmetic operator. These operators are also called shorthand assignment operators or compound
assignment operators.
JavaScript provides the following assignment operators:
Operator Name Description Example (a=3) Output
= Assignment It assigns the value of the right operand to the left operand. a = 3 3
+= Addition It adds right operand to the left operand and assigns the result to a += 3 6
assignment left operand. x+=3 is equivalent to x=x+3.
–= Subtraction It subtracts right operand from the left operand and assigns the a – = 3 0
assignment result to left operand. x–=3 is equivalent to x=x–3.
*= Multiplication It multiplies right operand with the left operand and assigns the a *= 3 9
assignment result to left operand. x*=3 is equivalent to x=x*3.
/= Division It divides left operand with the right operand and assigns the a /= 3 1
assignment result to left operand. x/=3 is equivalent to x=x/3.
%= Remainder It takes modulus of two operands and assigns the result to left a %= 3 0
assignment operand. x%=3 is equivalent to x=x%3.
**= Exponent It raises the value of a variable to the power of the right operand. a **= 3 27
assignment x = x**=3
Example: To multiply two numbers using multiplication assignment operator.
<HTML>
<BODY>
<SCRIPT>
var x = 10;
x *= 5;
document.writeln("output "+ x);
</SCRIPT>
</BODY>
</HTML>
JavaScript Part 1 337

