Q1. What is the Number Data Type in JavaScript?
The Number data type is used to store numeric values, including integers and decimal numbers.
JavaScript uses a single Number type for all numeric values.
Example
Both integer and floating-point values are stored using the Number data type.
JavaScript uses a single Number type for all numeric values.
Example
let age = 25;let price = 99.99;Both integer and floating-point values are stored using the Number data type.
Q2. Does JavaScript Have Separate Types for Integer and Float?
No, JavaScript does not have separate types for integers and floating-point numbers. Both are stored under the Number data type.
Example
JavaScript treats both values as Numbers.
Example
let a = 10; // Integerlet b = 10.5; // Floating pointJavaScript treats both values as Numbers.
Q3. What is NaN in JavaScript?
NaN stands for Not-a-Number. It represents an invalid numeric operation.
Example
Output
JavaScript cannot divide text by a number, so it returns NaN.
Example
let result = "Hello" / 2;console.log(result);Output
NaNJavaScript cannot divide text by a number, so it returns NaN.
Q4. How Can You Check if a Value is NaN?
JavaScript provides the isNaN() function to check whether a value is not a number.
Example
Output
Example
console.log(isNaN("Hello"));Output
trueQ5. What is Infinity in JavaScript?
Infinity is a special numeric value that represents a number greater than any other number.
Example
Output
Example
let value = 10 / 0;console.log(value);Output
Infinity