3 Example(s) of Javascript Arithmetic operators


Description :

Arithmetic operators are used to perform arithmetic operation. In this example, We have a variable with value as "100 + 50" so this will result in 150. See the code snippet:


Javascript Arithmetic operators Example - 1
<!DOCTYPE html>
<html>
 <head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
 <p id="sample"></p>
 <script>
 var x = 100 + 50; 
 document.getElementById("sample").innerHTML = x;
 </script>
</body>
</html>

Output

Description :

In this example, Arithmetic operation is (100 + 50)*a where a is 5 and this will result in 750. See the code snippet:


Javascript Arithmetic operators Example - 2
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<p id="sample"></p>
<script>
   var a=5;
   var x = (100 + 50)*a;
   document.getElementById("sample").innerHTML = x;
</script>
</body>
</html>

Output

Description :

In this example, Arithmetic operation is var x = 5; var y = 5; var z = x / y; Which will result 1 as output. See the code snippet:


Javascript Arithmetic operators Example - 3
<!DOCTYPE html>
<html>
 <head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
  <body>
<p id="sample"></p>
<script>
var x = 5;
var y = 5;
var z = x / y;
document.getElementById("sample").innerHTML = z;
</script>
      </body>
</html>

Output