Simple Assignment and Compound Assignment Operators
Simple Assignment ( = )
Multiple/Assign ( *= )
Divide/Assign ( /= )
Modulus/Assign ( %= )
Add/Assign ( += )
Subtract/Assign ( -= )
Left Shift/Assign ( <<= )
Signed Right Shift/Assign ( >>= )
Unsigned Right Shift/Assign ( >>>= )
Bitwise AND/Assign ( &= )
Bitwise XOR/Assign ( ^= )
Bitwise OR/Assign ( |= )




Navigation Aids -- This Page        Navigation Aids -- This Topic        Navigation Aids -- This Site




Review of Terms Related to This Topic





The Purpose for this Page

This page will show the basic rules for JavaScript assignment operator group. In addition, type conversions are discussed where applicable. Some special situation cases are explained. And finally, some scripting examples are provided with comments.





The Basics of Assignment Operators





Special Situations





Some Script Examples


Expression Giving x= Comment
x = 10;
x *= 5
50 multiply and assign
10 times 5 assigns 50 to x
x = 10;
x /= 5
2 divide and assign
10 divided by 5 giving a quotient of 2
x = 10;
x %= 3
1 modulus and assign
10 divided by 3 giving a remainder of 1
x = 10;
x += 2
12 add and assign
2 added to 10 giving 12
x = 10;
x -= 2
8 subtract and assign
2 subtracted from 10 giving 8
x = 4;
x <<= 2
16 left shift
00000100 shifted to the left two bits giving 00010000
x = -5;
x <<= 2
-20 left shift
11111011 shifted to the left two bits giving 11101100
x = 16;
x >>= 2
4 right shift with sign extended
00010000 shifted to the right two bits and left filled with sign bit giving 00000100
x = -9;
x >>= 2
-3 right shift with sign extended
11110111 shifted to the right two bits and left filled with sign bit giving 11111101
x = 16;
x >>>= 4
1 right shift with zero fill
00010000 shifted to the right four bits and left zero filled giving 00000001
x = -10;
x >>>= 3
30 right shift with zero fill
11110110 shifted to the right three bits and left zero filled giving 00011110
x = 11;
x &= 13
9 bitwise AND
00001011 AND with 00001101 giving 00001001
x = 11;
x |= 13
15 bitwise OR
00001011 OR with 00001101 giving 00001111
x = 11;
x ^= 13
6 bitwise XOR
00001011 XOR with 00001101 giving 00000110


Top            

Rx4AJAX        About Us | Topic Index | Contact Us | Privacy Policy | 2008 This Site Built By PPThompson