aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/javascript/reference/global_objects/math/sqrt/index.html
blob: 410ba30dd199e0a4cd0a4e54cded2aa9c08d1660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
title: Math.sqrt()
slug: Web/JavaScript/Reference/Global_Objects/Math/sqrt
translation_of: Web/JavaScript/Reference/Global_Objects/Math/sqrt
original_slug: Web/JavaScript/Referencia/Objetos_globales/Math/sqrt
---
<div>{{JSRef}}</div>

<p>La  función <strong><code>Math.sqrt()</code></strong> retorna la raíz cuadrada de un número, que es<math display="block"><semantics><mrow><mi>x</mi><mo></mo><mn>0</mn><mo>,</mo><mstyle mathvariant="monospace"><mrow><mi>M</mi><mi>a</mi><mi>t</mi><mi>h</mi><mo>.</mo><mi>s</mi><mi>q</mi><mi>r</mi><mi>t</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow></mstyle><mo>=</mo><msqrt><mi>x</mi></msqrt><mo>=</mo><mtext>the unique</mtext><mspace width="thickmathspace"></mspace><mi>y</mi><mo></mo><mn>0</mn><mspace width="thickmathspace"></mspace><mtext>such that</mtext><mspace width="thickmathspace"></mspace><msup><mi>y</mi><mn>2</mn></msup><mo>=</mo><mi>x</mi></mrow><annotation encoding="TeX">\forall x \geq 0, \mathtt{Math.sqrt(x)} = \sqrt{x} = \text{the unique} \; y \geq 0 \; \text{such that} \; y^2 = x</annotation></semantics></math></p>

<h2 id="Sintaxis">Sintaxis</h2>

<pre class="syntaxbox"><code>Math.sqrt(<var>x</var>)</code></pre>

<h3 id="Parámetros">Parámetros</h3>

<dl>
 <dt><code>x</code></dt>
 <dd>Un numero</dd>
</dl>

<h3 id="Valor_de_Retorno">Valor de Retorno</h3>

<p>La raíz cuadrada del número proporcionado. Si los números son negativos, {{jsxref("NaN")}} es devuelto.</p>

<h2 id="Descripción">Descripción</h2>

<p>Si el valor de <code>x</code> es negativo <code>Math.sqrt()</code> retorna {{jsxref("NaN")}}.</p>

<p>Debido a que <code>sqrt()</code> es un método estático de <code>Math</code>, siempre úsalo como <code>Math.sqrt()</code>, en lugar de un método del objeto <code>Math</code> que hayas creado (<code>Math</code> no es un constructor).</p>

<h2 id="Ejemplos">Ejemplos</h2>

<h3 id="Usando_Math.sqrt()">Usando <code>Math.sqrt()</code></h3>

<pre class="brush: js">Math.sqrt(9); // 3
Math.sqrt(2); // 1.414213562373095

Math.sqrt(1);  // 1
Math.sqrt(0);  // 0
Math.sqrt(-1); // NaN
</pre>

<h2 id="Especificaciones">Especificaciones</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Especificación</th>
   <th scope="col">Estado</th>
   <th scope="col">Comentario</th>
  </tr>
  <tr>
   <td>{{SpecName('ES1')}}</td>
   <td>{{Spec2('ES1')}}</td>
   <td>Definición inicial. Implementada en JavaScript 1.0.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.8.2.17', 'Math.sqrt')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-math.sqrt', 'Math.sqrt')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-math.sqrt', 'Math.sqrt')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilidad">Compatibilidad</h2>

{{Compat("javascript.builtins.Math.sqrt")}}

<h2 id="Ver_también">Ver también</h2>

<ul>
 <li>{{jsxref("Math.cbrt()")}}</li>
 <li>{{jsxref("Math.exp()")}}</li>
 <li>{{jsxref("Math.log()")}}</li>
 <li>{{jsxref("Math.pow()")}}</li>
</ul>