<!-- !
Number methods -->
1. isFinite
2. isInteger
3. isNaN
4. parseInt
5. parseFloat
1. [Link](value)
- Description:
Determines whether the provided value is a finite number. This method
returns `true` if the value is a finite number, and `false` if it is
`Infinity`, `-Infinity`, or `NaN`.
- Example:
[Link]([Link](123)); // true
[Link]([Link](Infinity)); // false
[Link]([Link]('123')); // false
[Link]([Link](NaN)); // false
2. [Link](value)
- Description: Determines whether the provided value is an integer. This
method returns `true` if the value is an integer, and `false` if it is not.
- Example:
[Link]([Link](123)); // true
[Link]([Link](123.45)); // false
[Link]([Link]('123')); // false
[Link]([Link](NaN)); // false
3. [Link](value)
- Description: Determines whether the provided value is `NaN` (Not-a-
Number). This method is a more robust version of the global `isNaN` function
and does not coerce the argument to a number before checking.
- Example:
[Link]([Link](NaN)); // true
[Link]([Link]('NaN')); // false
[Link]([Link](123)); // false
[Link]([Link](undefined)); // false
4. parseInt(string)
- Description:
Parses a string argument and returns an integer.
- Example:
[Link](parseInt('123')); // 123
[Link](parseInt('123abc')); // 123 (ignores 'abc')
[Link](parseInt('abc123')); // NaN
5. parseFloat(string)
- Description:
`parseFloat` is a JavaScript function that converts a string into a floating -
point number.
- Examples:
parseFloat('3.14'); // 3.14
parseFloat('3.14abc'); // 3.14 (stops parsing when 'a' is encountered)
parseFloat('abc3.14'); // NaN (not a valid number at the start)
parseFloat(' 42.5 '); // 42.5 (ignores leading and trailing whitespace)
parseFloat('42.5px'); // 42.5 (stops parsing when 'p' is encountered)
let num = Number(10)
[Link](num)
[Link](typeof num)
let num2 = Number("10")
[Link](num2)
[Link](typeof num2) //number
let num3 = Number("10abc")
[Link](num3) //NaN
[Link](typeof num3) //number
// ! Number Methods
// ! 1. [Link]()
let num4 = [Link]("10abc")
[Link](num4)
let num5 = [Link]("a4bc10")
[Link](num5)
[Link]('-------------------------------------------')
// ! how to take input from user => prompt() method
let a = prompt("enter one number")
[Link](a)
[Link](typeof a)
// ! take two numbers from users and add
let b = [Link]( prompt("enter first number"))
let c = [Link](prompt("enter second number"))
alert(b+c)
// ! 2. [Link]()
let num6 = 10000000;
let isFinite = [Link](num6) // true
[Link]([Link](2n)) // false (for bigInt)
[Link](isFinite)
[Link]([Link]("hello")) // false (for string)
[Link]('-----------------------------------------------')
// ! 3. [Link]()
let num7 = 1234.98
[Link]([Link](num7)) // false
[Link]([Link](2012)) // true
[Link]("-----------------------------------")
// ! isNaN()
// only if we pass number then only false , otherwise it will give true
[Link](isNaN(123)) // false
[Link](isNaN("san")) // true
[Link](isNaN(NaN)) // true
[Link](isNaN(2n)) // for bigInt it will give error
[Link]("----------------------------------------------------")
// ! 4 [Link]()
// only for NaN it will give true, otherwise it will give false
[Link]([Link](123)) // false
[Link]([Link]('santanu')) // false
[Link]([Link](NaN)) // true
// ! isNaN() vs [Link]() *****
[Link]("----------------------------------------")
// ! 5. [Link]()
[Link]([Link]("10.2x3abc")) // 10.2
[Link]([Link]("ab10.2x3abc")) // NaN