-
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 provides several built-in methods that can be used on number values. These methods help with tasks such as formatting decimals, converting types, checking values, and more.
let num = 123.456;
toString()
Converts a number to a string.
(123).toString(); // "123"
(255).toString(16); // "ff" (hexadecimal)
toFixed(n)
Formats a number using fixed-point notation.
let n = 5.6789;
n.toFixed(2); // "5.68"
Returns a string with n
digits after the decimal.
toPrecision(n)
Formats a number to n
total digits (includes digits before and after decimal).
let x = 123.456;
x.toPrecision(4); // "123.5"
valueOf()
Returns the primitive value of a number (often used internally).
let x = new Number(50);
x.valueOf(); // 50
Number.isInteger(value)
Checks if a value is an integer.
Number.isInteger(10); // true
Number.isInteger(10.5); // false
Number.isNaN(value)
Checks if a value is exactly NaN
(Not a Number).
Number.isNaN(NaN); // true
Number.isNaN("hello"); // false
Number.isNaN(Number("abc")); // true
parseInt()
and parseFloat()
Used to convert strings to numbers.
parseInt("123.45"); // 123
parseFloat("123.45"); // 123.45
Q1. How do you convert the number 150
into a string using toString()
?
Q2. How do you format the number 3.14159
to two decimal places using toFixed()
?
Q3. How do you use toPrecision()
to format the number 456.789
to 4 significant digits?
Q4. What is the result of valueOf()
when used on new Number(75)
?
Q5. How do you check if a number 20.5
is an integer using Number.isInteger()
?
Q6. How do you check if a variable x = "abc"
is NaN
after converting with Number()
?
Q7. How do you parse the string "55.99"
into a whole number using parseInt()
?
Q8. How do you parse the string "55.99"
into a floating-point number using parseFloat()
?
Q9. How do you convert the number 255
into a binary string using toString()
?
Q10. What is the difference between toFixed()
and toPrecision()
with an example?
Q1: What does (255).toString(16) return?
Q2: Which method formats a number to a specific number of decimal places?
Q3: What is the output of parseInt("123.456")?
Q4: What does Number.isInteger(10.0) return?
Q5: Which method checks if a value is exactly NaN?
Q6: What is the result of (123.456).toPrecision(5)?
Q7: Which method returns the primitive value of a number object?
Q8: What is the output of Number.isNaN("abc")?
Q9: Which method would you use to get the value 123.45 from the string "123.45abc"?
Q10: What will (5.6789).toFixed(2) return?