Math.E
Math.E 靜態資料屬性表示尤拉數(Euler's number),即自然對數的底數 e,其近似值為 2.718。
試一試
function compoundOneYear(interestRate, currentVal) {
return currentVal * Math.E ** interestRate;
}
console.log(Math.E);
// Expected output: 2.718281828459045
console.log((1 + 1 / 1000000) ** 1000000);
// Expected output: 2.718280469 (approximately)
console.log(compoundOneYear(0.05, 100));
// Expected output: 105.12710963760242
值
Math.E 的屬性特性 | |
|---|---|
| 可寫 | 否 |
| 可列舉 | 否 |
| 可配置 | 否 |
描述
因為 E 是 Math 的靜態屬性,所以你總是透過 Math.E 來使用它,而不是透過你自己建立的 Math 物件屬性來使用(Math 不是一個建構函式)。
示例
使用 Math.E
下面的函式返回 e
js
function getNapier() {
return Math.E;
}
getNapier(); // 2.718281828459045
規範
| 規範 |
|---|
| ECMAScript® 2026 語言規範 # sec-math.e |
瀏覽器相容性
載入中…