Math.sqrt()

  • Revision slug: JavaScript/Reference/Global_Objects/Math/sqrt
  • Revision title: sqrt
  • Revision id: 88052
  • Created:
  • Creator: Mgjbot
  • Is current revision? No
  • Comment robot Adding: [[ja:Core JavaScript 1.5 Reference:Global Objects:Math:sqrt]] <<langbot>>

Revision Content

Summary

Returns the square root of a number.

Method of Math

Static

Implemented in: JavaScript 1.0, NES 2.0
ECMA Version: ECMA-262

Syntax

Math.sqrt(x)

Parameters

x 
A number.

Description

If the value of number is negative, sqrt returns NaN.

Because sqrt is a static method of Math, you always use it as Math.sqrt(), rather than as a method of a Math object you created.

Examples

Example: Using Math.sqrt

The following function returns the square root of the variable x:

function getRoot(x) {
   return Math.sqrt(x)
}

If you pass getRoot the value 9, it returns 3; if you pass it the value 2, it returns 1.414213562373095.

{{ languages( { "fr": "fr/R\u00e9f\u00e9rence_de_JavaScript_1.5_Core/Objets_globaux/Math/sqrt", "ja": "ja/Core_JavaScript_1.5_Reference/Global_Objects/Math/sqrt", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/Math/sqrt" } ) }}

Revision Source

<p>
</p>
<h3 name="Summary"> Summary </h3>
<p>Returns the square root of a number.
</p>
<table class="fullwidth-table">
<tbody><tr>
<td class="header" colspan="2">Method of <a href="en/Core_JavaScript_1.5_Reference/Objects/Math">Math</a></td>
</tr>
<tr>
<td colspan="2">
<p><b>Static</b>
</p>
</td>
</tr>
<tr>
<td>Implemented in:</td>
<td>JavaScript 1.0, NES 2.0</td>
</tr>
<tr>
<td>ECMA Version:</td>
<td>ECMA-262</td>
</tr>
</tbody></table>
<h3 name="Syntax"> Syntax </h3>
<p><code>
Math.sqrt(<i>x</i>)
</code>
</p>
<h3 name="Parameters"> Parameters </h3>
<dl><dt> <code>x</code> </dt><dd> A number.
</dd></dl>
<h3 name="Description"> Description </h3>
<p>If the value of <code>number</code> is negative, <code>sqrt</code> returns <code>NaN</code>.
</p><p>Because <code>sqrt</code> is a static method of <code>Math</code>, you always use it as <code>Math.sqrt()</code>, rather than as a method of a <code>Math</code> object you created.
</p>
<h3 name="Examples"> Examples </h3>
<h4 name="Example:_Using_Math.sqrt"> Example: Using <code>Math.sqrt</code> </h4>
<p>The following function returns the square root of the variable <code>x</code>:
</p>
<pre>function getRoot(x) {
   return Math.sqrt(x)
}
</pre>
<p>If you pass <code>getRoot</code> the value 9, it returns 3; if you pass it the value 2, it returns 1.414213562373095.
</p>
<div class="noinclude">
</div>
{{ languages( { "fr": "fr/R\u00e9f\u00e9rence_de_JavaScript_1.5_Core/Objets_globaux/Math/sqrt", "ja": "ja/Core_JavaScript_1.5_Reference/Global_Objects/Math/sqrt", "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/Math/sqrt" } ) }}
Revert to this revision