036_赋值运算符
1. 簡(jiǎn)單的賦值運(yùn)算符由等號(hào)(=)實(shí)現(xiàn), 只是把等號(hào)右邊的值賦予等號(hào)左邊的變量。
2. 復(fù)合賦值運(yùn)算符是由加性運(yùn)算符、乘性運(yùn)算符或位移運(yùn)算符加等號(hào)(=)實(shí)現(xiàn)的:
- 加法/賦值(+=)
- 減法/賦值(-=)
- 乘法/賦值(*=)
- 除法/賦值(/=)
- 取模/賦值(%=)
- 左移/賦值(<<=)
- 有符號(hào)右移/賦值(>>=)
- 無(wú)符號(hào)右移/賦值(>>>=)
3. 復(fù)合賦值運(yùn)算是加性運(yùn)算、乘性運(yùn)算或位移運(yùn)算計(jì)算表達(dá)式的簡(jiǎn)寫形式。
4. 例子
4.1. 代碼
<!DOCTYPE html> <html lang="zh-CN"><head><meta charset="utf-8" /><title>賦值運(yùn)算符</title></head><body><script type="text/javascript">var a = 32;document.write('a = ' + a + '<br />');document.write('(a += 4) = ' + (a += 4) + '<br />');document.write('(a -= 2) = ' + (a -= 2) + '<br />');document.write('(a *= 2) = ' + (a *= 2) + '<br />');document.write('(a /= 2) = ' + (a /= 2) + '<br />');document.write('(a %= 5) = ' + (a %= 5) + '<br />');document.write('(a <<= 3) = ' + (a <<= 3) + '<br />');document.write('(a >>= 2) = ' + (a >>= 2) + '<br />');document.write('(a >>>= 2) = ' + (a >>>= 2) + '<br />');</script></body> </html>4.2. 效果圖
總結(jié)