JavaScript | Math.sqrt( ) function

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

Math.sqrt(value)

Parameters: This function accepts a single parameter value which hold the number whose square root is to be calculated.
Returns: Square root of the number passed as parameter passed as parameter.

Example:

Input  : Math.sqrt(4)
Output : 2

Input  : Math.sqrt(-4)
Output : NaN

Errors and Exceptions:

  • A non-numeric string passed as parameter returns NaN
  • An array with more than 1 integer passed as parameter returns NaN
  • A negative number passed as parameter returns NaN
  • An empty string passed as parameter returns NaN
  • An empty array passed as parameter returns NaN

Below are some examples that illustrate the Math.floor() function in JavaScript: