Math floor JavaScript | Rounds a number down and returns an integer value

JavaScript floor Method is used to Round a number downward to its nearest integer. It required a single parameter value which is number you want to be rounded to its nearest integer.

The Math.floor() function returns the largest integer less than or equal to a given number.

Note: If the passed argument is an integer, the value will not be rounded.

Syntax

Math floor JavaScript Example

Output: 7

Q: What if we passed a non-numeric string as a parameter in the JS floor method?

Answer: If the non-numeric string passed as a parameter then it will return NaN.

Math floor JavaScript

Q: Will JS throw an error if the passing value in the JS floor method non-numeric?

Answer: No it will not throw an error if the passing value is non-numeric only. It will return NaN on the following conditions:-

  •  A non-numeric string 
  • Array with more than 1 integer 
  • Empty variable 
  • Empty string 
  • Empty array 

Do comment if you have any doubts and questions on this tutorial.

Note: The All JS Examples codes are tested on the Safari browser (Version 12.0.2) and Chrome.
OS: macOS 10.14 Mojave
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.