La funzione Math.pow()
restituisce la potenza della base che si desidera moltiplicare per se stessa a seconda del valore dell'esponenete, cioè baseesponente
.
Sintassi
Math.pow(base, esponente)
Parametri
base
- La basee del numero.
esponente
- L'esponente usato per elevare la base.
Valore di Ritorno
Un numero che rappresenta la base elevata alla potenza dell'esponente.
Descrizione
Siccome pow()
è un metodo static di Math
, lo usi sempre nella forma Math.pow()
, piuttosto che come un metodo di un oggetto Math
da te creato (Math
non ha costruttori).
Esempi
Usando Math.pow()
// semplice
Math.pow(7, 2); // 49
Math.pow(7, 3); // 343
Math.pow(2, 10); // 1024
// esponenti fratti
Math.pow(4, 0.5); // 2 (radice quadrata di 4)
Math.pow(8, 1/3); // 2 (radice cubica di 8)
Math.pow(2, 0.5); // 1.4142135623730951 (radice quadrata di 2)
Math.pow(2, 1/3); // 1.2599210498948732 (radice cubica di 2)
// esponenti negativi
Math.pow(7, -2); // 0.02040816326530612 (1/49)
Math.pow(8, -1/3); // 0.5
// basi negative
Math.pow(-7, 2); // 49 (i quadrati son sempre positivi)
Math.pow(-7, 3); // -343 (i cubi possono essere negativi)
Math.pow(-7, 0.5); // NaN (i numeri negativi non hanno una quadrata reale)
// Siccome le radici "pari" e quelle "dispari" sono vicine tra loro,
// e i limiti della precisione numerica per i valori di tipo float,
// le basi negative con esponenti fratti ritornano sempre NaN
Math.pow(-7, 1/3); // NaN
Specifiche Tecniche
Specificazione | Status | Commento |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard |
Definizione iniziale. Implementata in JavaScript 1.0. |
ECMAScript 5.1 (ECMA-262) The definition of 'Math.pow' in that specification. |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Math.pow' in that specification. |
Standard | |
ECMAScript Latest Draft (ECMA-262) The definition of 'Math.pow' in that specification. |
Draft |
Compatiblità 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) |