Math.sqrt()
La funzione Math.sqrt()
ritorna la radice quadrata di un numero, cioè :
Sintassi
Math.sqrt(x)
Parametri
x
- Un numero.
Valore di ritorno
La radice quadrata di un dato numero. Se il numero è negativo viene ritornato NaN
.
Descrizione
Se il segno di x
è negativo, Math.sqrt()
ritorna NaN
.
Siccome sqrt()
è un metodo static di Math
, puoi usarlo sempre come Math.sqrt()
, piutttosto che come un metodo di un oggetto di tipo Math
creato da te (Math
non è un costruttore).
Esempio
Uso di Math.sqrt()
Math.sqrt(9); // 3
Math.sqrt(2); // 1.414213562373095
Math.sqrt(1); // 1
Math.sqrt(0); // 0
Math.sqrt(-1); // NaN
Specificazioni
Specification | Status | Comment |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | Definizione iniziale. Implementato per JavaScript 1.0. |
ECMAScript 5.1 (ECMA-262) The definition of 'Math.sqrt' in that specification. |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Math.sqrt' in that specification. |
Standard | |
ECMAScript (ECMA-262) The definition of 'Math.sqrt' in that specification. |
Living Standard |
Compatibilità browser
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |