DEV Community

loading...

Some Javascript Function

rianislam profile image Rian Islam ・2 min read
  1. Map Map is a collection of keyed data items, just like an Object. But the main difference is that Map allows keys of any type.

const arrayMap= [1, 4, 9, 16];

// pass a function to map
const map1 = arrayMap.map(x => x * 2);

console.log(map1);
// expected output: Array [2, 8, 18, 32]

  1. isNaN The isNaN() function determines whether a value is an illegal number (Not-a-Number). This function returns true if the value equates to NaN. Otherwise, it returns false. This function is different from the Number specific Number.isNaN() method.

3.JavaScript parseFloat() Function
The parseFloat() function is used to accept the string and convert it into a floating-point number. If the string does not contain a numeral value or If the first character of the string is not a Number then it returns NaN i.e, not a number. It actually returns a floating-point number parsed up to that point where it encounters a character that is not a Number.
Example 1: The parseFloat() function ignores leading and trailing spaces and returns the floating point Number of the string.
Input : var n = parseFloat(" 2018 ");
Output: n=2018 (floating point Number)
4.JavaScript Math abs( ) Method
The Math.abs() method is used to return the absolute value of a number. It takes a number as its parameter and returns its absolute value.
Syntax:
Math.abs(value)
5.JavaScript ceil() Method
The ceil() method rounds a number UPWARDS to the nearest integer, and returns the result.
Syntax
Math.ceil(x)
6.The static function Math.min() returns the lowest-valued number passed into it, or NaN if any parameter isn't a number and can't be converted into one.Math.min()
console.log(Math.min(2, 3, 1));
// expected output: 1

console.log(Math.min(-2, -3, -1));
// expected output: -3

const array1 = [2, 3, 1];

console.log(Math.min(...array1));
// expected output: 1
7.Math.max()

The Math.max() function returns the largest of the zero or more numbers given as input parameters, or NaN if any parameter isn't a number and can't be converted into one.
8.JavaScript Random
Math.random() returns a random number between 0 (inclusive), and 1 (exclusive):
Example
Math.random();
9.JavaScript: Math round() function
In JavaScript, round() is a function that is used to return a number rounded to the nearest integer value. Because the round() function is a static function of the Math object, it must be invoked through the placeholder object called Math.

  1. JavaScript Math sqrt( ) Method The Math.sqrt() method in JavaScript is used to square root of the number passed as a parameter to the function. Syntax Math.sqrt(value)

Discussion (0)

Forem Open with the Forem app