-
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
In JavaScript, numbers are always stored as floating-point values (even whole numbers).
let x = 10; // integer
let y = 10.5; // floating-point
JavaScript does not differentiate between integers and floats like some other languages.
Type | Example |
---|---|
Integer | 10 , -25 |
Float (decimal) | 3.14 , -0.01 |
Exponential | 5e3 → 5000 |
Hexadecimal | 0xFF → 255 |
Octal | 0o10 → 8 |
Binary | 0b1010 → 10 |
Method | Description | Example |
---|---|---|
toString() |
Converts to string | (123).toString() → "123" |
toFixed(n) |
Formats with n decimals |
(3.1415).toFixed(2) → "3.14" |
toPrecision(n) |
Formats to specified length | (123.456).toPrecision(4) → "123.5" |
valueOf() |
Returns primitive number | (123).valueOf() → 123 |
Number.isInteger(x) |
Checks if a value is an integer | true or false |
Number.isNaN(x) |
Checks if value is NaN |
true or false |
Value | Description |
---|---|
Infinity |
A number beyond upper limit |
-Infinity |
A number beyond lower limit |
NaN |
"Not a Number" |
let a = 1 / 0; // Infinity
let b = "abc" - 2; // NaN
Number("123"); // 123
parseInt("123.45"); // 123
parseFloat("123.45"); // 123.45
Number.MAX_VALUE // Largest possible number
Number.MIN_VALUE // Smallest positive number
Number.MAX_SAFE_INTEGER // 2^53 - 1
Number.MIN_SAFE_INTEGER // -(2^53 - 1)
Q1. How do you declare a floating-point number 3.14
and store it in a variable pi
?
Q2. How do you convert the string "45"
into a number using the Number()
function?
Q3. What is the output of (10).toFixed(2)
and what does it represent?
Q4. How do you check if 25.0
is an integer using Number.isInteger()
?
Q5. What is the result of typeof NaN
and how is it interpreted in JavaScript?
Q6. How do you write the number 5000
using exponential notation?
Q7. How do you convert 255
into a hexadecimal string using toString()
?
Q8. How do you find the largest number representable in JavaScript?
Q9. How do you check whether the result of "abc" - 5
is NaN
?
Q10. How do you safely convert a decimal number like "3.14159"
to a float?
Q1: Which of the following is a valid number in JavaScript?
Q2: What is the type of NaN in JavaScript?
Q3: What does (123.456).toFixed(1) return?
Q4: Which method checks if a number is an integer?
Q5: Which function would you use to convert "3.14" to a number?
Q6: What is the result of 1 / 0 in JavaScript?
Q7: What does typeof Infinity return?
Q8: Which of these values is not a finite number?
Q9: Which property gives the maximum safe integer in JS?
Q10: What does parseInt("45.67") return?