Math.sqrt()

La función Math.sqrt() retorna la raíz cuadrada de un número, que es x 0 , M a t h . s q r t ( x ) = x = the unique y 0 such that y 2 = x \forall x \geq 0, \mathtt{Math.sqrt(x)} = \sqrt{x} = \text{the unique} ; y \geq 0 ; \text{such that} ; y^2 = x

Sintaxis

Math.sqrt(x)

Parámetros

x

Un numero

Valor de Retorno

La raíz cuadrada del número proporcionado. Si los números son negativos, NaN es devuelto.

Descripción

Si el valor de x es negativo Math.sqrt() retorna NaN.

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

Ejemplos

Usando Math.sqrt()

js
Math.sqrt(9); // 3
Math.sqrt(2); // 1.414213562373095

Math.sqrt(1); // 1
Math.sqrt(0); // 0
Math.sqrt(-1); // NaN

Especificaciones

Specification
ECMAScript Language Specification
# sec-math.sqrt

Compatibilidad con navegadores

BCD tables only load in the browser

Ver también