//林中誠動態網頁設計
<!DOCTYPE html><html><head><meta charset="utf-8"/><title>Ch5_5_2.htm</title></head><body><h2>算術運算子的使用</h2><hr><script>var x, y;var intInc = 50;var intDec = 50;var strTitle1 = "JavaScript是"var strTitle2 = "一種網頁設計技術"document.write("負號運算: -8 = " + -8 + "<br/>");intInc++;document.write("遞增運算: A++ = " + intInc + "<br/>");intDec--;document.write("遞減運算: A-- = " + intDec + "<br/>");document.write("乘法運算: 6 * 7 = " + 6*7 + "<br/>");document.write("除法運算: 8 / 3 = " + 8/3 + "<br/>");document.write("餘數運算: 8 % 3 = " + 8%3 + "<br/>");document.write("加法運算: 5 + 4 = " + (5+4) + "<br/>"); document.write("減法運算: 5 - 4 = " + (5-4) + "<br/><hr/>");// 測試Pre-/Post- 運算子x = 50;y = 50;document.write("x++ = " +x+++":x = " + x + "<br/>");document.write("--y = " +--y+":y = " + y + "<br/><hr/>");document.write("字串連接: " + (strTitle1+strTitle2) + "<br/>");</script></body></html>
負號運算: -8 = -8遞增運算: A++ = 51遞減運算: A-- = 49乘法運算: 6 * 7 = 42除法運算: 8 / 3 = 2.6666666666666665餘數運算: 8 % 3 = 2加法運算: 5 + 4 = 9減法運算: 5 - 4 = 1
x++ = 50:x = 51--y = 49:y = 49
字串連接: JavaScript是一種網頁設計技術