要执行JavaScript中的+,-,*等基本数学运算,请使用运算符。JavaScript包括基本数学运算符,例如加法,减法,乘法等。
您可以尝试运行以下代码,以学习如何使用基本数学,即JavaScript中的数学运算符-
<html> <body> <script> var a = 77; var b = 30; var c = "Demo"; var linebreak = "<br />"; document.write("a + b = "); result = a + b; document.write(result); document.write(linebreak); document.write("a - b = "); result = a - b; document.write(result); document.write(linebreak); document.write("a / b = "); result = a / b; document.write(result); document.write(linebreak); document.write("a % b = "); result = a % b; document.write(result); document.write(linebreak); document.write("a + b + c = "); result = a + b + c; document.write(result); document.write(linebreak); a = ++a; document.write("++a = "); result = ++a; document.write(result); document.write(linebreak); b = --b; document.write("--b = "); result = --b; document.write(result); document.write(linebreak); </script> </body> </html>