ES6 - Math sqrt() Function



This method returns the square root of a number. If the value of a number is negative, sqrt returns NaN.

Syntax

Math.sqrt ( x );  

Parameter

  • x − represents a number

Return Value

Returns the square root of the number.

Example

console.log("---Math.sqrt()---") 
console.log("Math.sqrt(16) : "+Math.sqrt(16) 
console.log("Math.sqrt(15.5) : "+Math.sqrt(15.5))           

Output

---Math.sqrt()--- 
Math.sqrt(16) : 4 
Math.sqrt(15.5) : 3.9370039370059056             
Advertisements