Javascript Math sqrt()

Introduction

The Math.sqrt() function returns the square root of a number.

Math.sqrt(x) // x is a number.

If the number is negative, NaN is returned.

If the value of x is negative, Math.sqrt() returns NaN.

let a = Math.sqrt(9); // 3
console.log(a);//from  w w w  .  j a v  a  2 s.  c o  m
a = Math.sqrt(2); // 1.414213562373095
console.log(a);
a = Math.sqrt(1);  // 1
console.log(a);
a = Math.sqrt(0);  // 0
console.log(a);
a = Math.sqrt(-1); // NaN
console.log(a);
a = Math.sqrt(-0); // -0
console.log(a);



PreviousNext

Related