JavaScript & jQuery Tutorials

JS Home Right Arrow JS Reference Right Arrow Math Right Arrow sqrt()

sqrt()  Math  class method

Description

Returns the positive square root of a number.

  • Like all class methods sqrt() should be used on the class rather than an instance of the class.

Syntax


Signature Description
Math.sqrt(value)Returns the positive square root of a number.

Parameters


Parameter Description
valueThe value you wish to find the sqrt() of:
  • Negative numbers returns NaN.
  • Non-numeric strings returns NaN.
  • Passing no parameter returns NaN.
  • Passing null returns 0.

Examples

The code below displays sqrt() usage.


// Store results in an array.
var sqrtValues = new Array(6);
sqrtValues[0] = Math.sqrt(1.49);
sqrtValues[1] = Math.sqrt(-10.5);
sqrtValues[2] = Math.sqrt('100.5');
sqrtValues[3] = Math.sqrt('five');
sqrtValues[4] = Math.sqrt();
sqrtValues[5] = Math.sqrt(null);
alert(sqrtValues);  

Press the button below to action the above code:

Related Tutorials

JavaScript Advanced Tutorials - Lesson 4 - Math



  

go to home page Homepage go to top of page Top