Number methods are built-in functions used to work with numbers.
In JavaScript, we use two dots . to call a method.
let num = 10.5;
num.toString();
Converts a number to a string.
let num = 100;
let result = num.toString();
console.log(result); // "100"
Rounds a number and keeps a fixed number of decimal places.
let num = 10.5678;
num.toFixed(2); // "10.57"
Extracts an integer from a string.
parseInt("100px"); // 100
parseInt("50.5"); // 50
Extracts a floating-point number from a string.
parseFloat("50.75px"); // 50.75
Checks if a value is an integer.
Number.isInteger(10); // true
Number.isInteger(10.5); // false
Checks if a value is NaN (Not a Number).
Number.isNaN(NaN); // true
Number.isNaN("abc"); // false
Click the button to see number methods in action: