JavaScript log() 方法
定義和用法
log() 方法可返回一個(gè)數(shù)的自然對數(shù)。
語法
Math.log(x)
參數(shù) | 描述 |
---|---|
x | 必需。任意數(shù)值或表達(dá)式。 |
返回值
x 的自然對數(shù)。
說明
參數(shù) x 必須大于 0。
實(shí)例
在本例中,我們將對不同的數(shù)運(yùn)用 log() :
<script type="text/javascript"> document.write(Math.log(2.7183) + "<br />") document.write(Math.log(2) + "<br />") document.write(Math.log(1) + "<br />") document.write(Math.log(0) + "<br />") document.write(Math.log(-1)) </script>
輸出:
1.0000066849139877 0.6931471805599453 0 -Infinity NaN
TIY
- log()
- 如何使用 log 方法。