math.floor in javascript code example

Example 1: math.floor js

console.log(Math.floor(5.95));
// expected output: 5

console.log(Math.floor(5.05));
// expected output: 5

console.log(Math.floor(5));
// expected output: 5

console.log(Math.floor(-5.05));
// expected output: -6

Example 2: ~~ in javascript

~~ used to convert some types to int (32 bit int)

Example 3: math.max in javascript

Math.max() function returns the largest of the zero or more numbers given as input parameters.
Math.max(1,10,100); // return 100

Example 4: javascript round down

Math.floor(x);

Example 5: array.unshift in javascript

//The unshift() method adds one or more elements to the beginning of an array 
//and returns the new length of the array.

const array1 = [1, 2, 3];
console.log(array1.unshift(4, 5));
// expected output: 5
console.log(array1);
// expected output: Array [4, 5, 1, 2, 3]

Example 6: math.round in javascript

let xo =7.45;
xo = Math.round(xo);
// output = 7;