-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
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 Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
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 Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JavaScript supports standard arithmetic operators to perform mathematical calculations.
These operators work with numbers and return numeric results.
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 |
Arithmetic works with both integers and floats
You can use parentheses ()
to change operator precedence
Exponentiation (**
) was added in ES2016 (ES7)
let a = 10, b = 3;
let sum = a + b;
let power = a ** b;
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)
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
?
Q1: What is the result of 7 % 3?
Q2: Which operator is used for exponentiation in JavaScript?
Q3: What is the output of this code?let x = 5; console.log(x++);
Q4: What will 10 / 2 return?
Q5: Which operator returns the remainder of a division?
Q6: What is the result of 3 + 4 * 2 without parentheses?
Q7: What is the correct way to ensure addition happens before multiplication in 3 + 4 * 2?
Q8: Which operator is used to decrease the value of a variable by 1?
Q9: What will 2 ** 3 return in JavaScript?
Q10: What is the result of 10 % 2?