Math.sqrt()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

La función Math.sqrt() retorna la raíz cuadrada de un número, que es

x0,Math.sqrt(x)=x=the uniquey0such thaty2=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® 2025 Language Specification
# sec-math.sqrt

Compatibilidad con navegadores

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
sqrt

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Ver también