JavaScript

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

JavaScript

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

JS Arithmetic


📘 JavaScript Arithmetic – Performing Math in JavaScript

JavaScript supports standard arithmetic operators to perform mathematical calculations.

These operators work with numbers and return numeric results.


🔹 JavaScript Arithmetic Operators
Operator Name Example Result
+ Addition 5 + 2 7
- Subtraction 5 - 2 3
* Multiplication 5 * 2 10
/ Division 5 / 2 2.5
% Modulus 5 % 2 1
** Exponentiation 5 ** 2 25
++ Increment x++ x + 1
-- Decrement x-- x - 1

🧠 Important Notes:
  • Arithmetic works with both integers and floats

  • You can use parentheses () to change operator precedence

  • Exponentiation (**) was added in ES2016 (ES7)


🔁 Arithmetic with Variables
let a = 10, b = 3;
let sum = a + b;
let power = a ** b;

📌 Increment & Decrement Examples
let x = 5;
x++; // x becomes 6
x--; // x becomes 5 again

Prefix vs Postfix:

let a = 10;
console.log(++a); // 11 (prefix)
console.log(a++); // 11 (postfix, then becomes 12)

Practice Questions

Q1. How do you add two variables a = 10 and b = 15 and store the result in sum?

Q2. How do you subtract variable b = 5 from a = 20 and print the result?

Q3. How do you multiply x = 4 and y = 5 using the * operator?

Q4. How do you divide 25 by 4 using the / operator and print the result?

Q5. How do you find the remainder when 15 is divided by 4 using the % operator?

Q6. How do you calculate 3 raised to the power of 4 using the ** operator?

Q7. How do you increment a variable counter by 1 using both counter++ and ++counter?

Q8. How do you decrement a variable level from 10 to 9 using the decrement operator?

Q9. How do you use arithmetic operators to calculate the average of three numbers a = 5, b = 10, c = 15?

Q10. How do you use parentheses to ensure that addition occurs before multiplication in the expression 5 + 3 * 2?


JS Arithmetic Quiz

Q1: What is the result of 7 % 3?

A. 0
B. 1
C. 2
D. 3

Q2: Which operator is used for exponentiation in JavaScript?

A. ^
B. exp
C. **
D. ^^

Q3: What is the output of this code?let x = 5; console.log(x++);

A. 5
B. 6
C. 4
D. Error

Q4: What will 10 / 2 return?

A. 4
B. 5
C. 2
D. 0

Q5: Which operator returns the remainder of a division?

A. /
B. **
C. %
D. //

Q6: What is the result of 3 + 4 * 2 without parentheses?

A. 14
B. 11
C. 7
D. 8

Q7: What is the correct way to ensure addition happens before multiplication in 3 + 4 * 2?

A. 3 + 4 * 2
B. (3 + 4) * 2
C. 3 + (4 * 2)
D. (3 * 2) + 4

Q8: Which operator is used to decrease the value of a variable by 1?

A. --
B. ++
C. -
D. +=

Q9: What will 2 ** 3 return in JavaScript?

A. 6
B. 8
C. 9
D. 16

Q10: What is the result of 10 % 2?

A. 0
B. 1
C. 2
D. 5

Go Back Top