-
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 has a built-in Math
object that allows you to perform mathematical calculations, including rounding, finding min/max, generating random numbers, and more.
📌 The Math
object is not a constructor, so you don’t use new Math()
.
Math
MethodsMethod | Description | Example |
---|---|---|
Math.round(x) |
Rounds x to the nearest integer |
Math.round(4.6) → 5 |
Math.floor(x) |
Rounds x down |
Math.floor(4.9) → 4 |
Math.ceil(x) |
Rounds x up |
Math.ceil(4.1) → 5 |
Math.trunc(x) |
Removes the decimal (keeps integer part) | Math.trunc(4.9) → 4 |
Math.pow(x, y) |
x to the power of y |
Math.pow(2, 3) → 8 |
Math.sqrt(x) |
Square root of x |
Math.sqrt(25) → 5 |
Math.abs(x) |
Absolute value (no sign) | Math.abs(-5) → 5 |
Math.min(x, y, ...) |
Minimum value among arguments | Math.min(1, 5, 0) → 0 |
Math.max(x, y, ...) |
Maximum value among arguments | Math.max(1, 5, 0) → 5 |
Math.random() |
Random number between 0 and 1 |
Math.random() → 0.34 |
Function | Description | Math.round(4.5) |
Math.ceil(4.5) |
Math.floor(4.5) |
Math.trunc(4.5) |
---|---|---|---|---|---|
Round to nearest | 5 | 5 | 5 | 4 | 4 |
// Random number between 0 and 9
Math.floor(Math.random() * 10);
// Random number between 1 and 100
Math.floor(Math.random() * 100) + 1;
Q1. How do you round the number 4.6
to the nearest integer using Math.round()
?
Q2. How do you get the square root of 49
using a Math method?
Q3. What is the output of Math.floor(5.9)
and what does it represent?
Q4. How do you round up the number 4.1
using Math.ceil()
?
Q5. How do you raise 2
to the power 5
using Math.pow()
?
Q6. How do you generate a random number between 0
and 1
using Math?
Q7. How do you get the maximum number from a list like (4, 9, 1)
using Math?
Q8.How do you convert -10
into a positive number using Math.abs()
?
Q9. What does Math.trunc(4.7)
return and why?
Q10. How do you generate a random integer between 1 and 50 in JavaScript?
Q1: What does Math.round(4.5) return?
Q2: What is the output of Math.floor(4.9)?
Q3: What is returned by Math.pow(3, 2)?
Q4: Which method gives the square root of a number?
Q5: What does Math.abs(-100) return?
Q6: What is the result of Math.ceil(5.2)?
Q7: What does Math.random() return?
Q8: What is the purpose of Math.trunc()?
Q9: Which method gives the largest number from a group?
Q10: Which of the following will return a random integer between 1 and 10?