Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

JavaScript Arithmetic Operators

by suresh

The JavaScript Arithmetic Operators include operators like Addition, Subtraction, Multiplication, Division, and Modulus. All these operators are binary operators, which means they operate on two operands.

The below table shows the Arithmetic Operators in JavaScript with examples.

JS Arithmetic OperatorsOperationExample
+Addition10 + 2 = 12
–Subtraction10 – 2 = 8
*Multiplication10 * 2 = 20
/Division10 / 2 = 5
%Modulus – It returns the remainder after the division10 % 2 = 0 (Here remainder is zero). If it is 10 % 3 then it will be 1.

JavaScript Arithmetic Operators Example

For this JavaScript Arithmetic operations example, We are using two variables a and b, and their values are 12 and 3.

We are going to use these two variables to perform various arithmetic operations in JavaScript Programming Language

<!DOCTYPE html>
<html>
<head>
    <title>Javascript Arithmetic Operators</title>
</head>
<body>
    <h1>Performing Arithmetic Operations </h1>
<script>
   var a = 12, b = 3;
   var addition, subtraction, multiplication, division, modulus;

   addition = a + b; //addition of 3 and 12
   subtraction = a - b; //subtract 3 from 12
   multiplication = a * b; //Multiplying both
   division = a / b; //dividing 12 by 3 (number of times)
   modulus = a % b; //calculation the remainder

   document.write("Addition of " + a +' and ' + b +" is = " + addition + "<br />");
   document.write("Subtraction of " + a +' and ' + b +" is = " + subtraction + "<br />");
   document.write("Multiplication of " + a +' and ' + b +" is = " + multiplication + "<br />");
   document.write("Division of " + a +' and ' + b +" is = " + division + "<br />");
   document.write("Modulus of " + a +' and ' + b +" is = " + modulus + "<br />");
</script>
</body>
</html>

OUTPUT

JavaScript Arithmetic Operators 1

JavaScript Arithmetic Operations Example 2

For this JavaScript example also, We are using two variables a and b and their values are 12 and 3.

Here. we are going to use these variables to show you, How to display the JavaScript output in Paragraphs.

<!DOCTYPE html>
<html>
<head>
    <title>Javascript Arithmetic Operators 2</title>
</head>
<body>
    <h1>Performing Arithmetic Operations </h1>
    <p id = 'add'> Addition </p>
    <p id = 'sub'> Subtraction </p>
    <p id = 'mul'> Multiplication </p>
    <p id = 'div'> Division </p>
    <p id = 'mod'> Modulus </p>
<script>
   var a = 12, b = 3;
   var add, sub, mul, div, mod;

   add = a + b; //addition of 3 and 12
   sub = a - b; //subtract 3 from 12
   mul = a * b; //Multiplying both
   div = a / b; //dividing 12 by 3 (number of times)
   mod = a % b; //calculation the remainder

   document.getElementById("add").innerHTML = "Addition of " + a +' and ' + b +" is = " + add;
   document.getElementById("sub").innerHTML = "Subtraction of " + a +' and ' + b +" is = " + sub;
   document.getElementById("mul").innerHTML = "Multiplication of " + a +' and ' + b +" is = "+ mul;
   document.getElementById("div").innerHTML = "Division of " + a +' and ' + b +" is = " +  div;
   document.getElementById("mod").innerHTML = "Modulus of " + a +' and ' + b +" is = " +  mod;
</script>
</body>
</html>

OUTPUT

JavaScript Arithmetic Operators 2

Placed Under: JavaScript

  • SQL DML, DDL, DCL & TCL Cmds
  • SQL NOT EXISTS Operator
  • SQL UPDATE from SELECT
  • SQL AFTER UPDATE Triggers
  • SQL Get Column Names in Table
  • SQL IF ELSE
  • SQL ACID Properties
  • SQL FOR XML PATH
  • Java Two Dimensional Array
  • Java Perfect Number Program
  • Java Count Digits in a Number
  • C Compare Two Strings Program
  • C Print Prime Numbers 1 to 100
  • C program to Reverse a String
  • C Palindrome Number Program
  • C Program for Palindrome String
  • C Remove Duplicate String Chars
  • C Square of a Number Program
  • C Sum and Average of N Number
  • Python Fibonacci Series program
  • Python Area Of Circle Program
  • Python Prime Numbers 1 to 100
  • Python Program for Leap Year
  • Tableau Rank Calculation
  • Tableau Google Maps usage
  • Power BI Format Dates
  • Power BI Top 10 Filters
  • Power BI – Create Hierarchy
  • Power BI DAX Math Functions
  • Learn SSIS in 28 Days
  • SSIS Transformations
  • SSIS Incremental Load
  • SSRS Drill Through Reports
  • SSRS Drill Down Reports
  • R Programming Tutorial
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy