Math.LN2

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 propriété Math.LN2 représente le logarithme naturel de 2, environ 0.693:

Math.LN2=ln(2)0.693\mathtt{\mi{Math.LN2}} = \ln(2) \approx 0.693

Exemple interactif

function getNatLog2() {
  return Math.LN2;
}

console.log(getNatLog2());
// Expected output: 0.6931471805599453
Attributs de Math.LN2
ÉcrivableNon
ÉnumérableNon
ConfigurableNon

Description

LN2 est une propriété statique de l'objet Math, il doit toujours être utilisé avec la syntaxe Math.LN2, et non pas être utilisé comme la propriété d'un objet qui aurait été créé (Math n'est pas un constructeur).

Exemples

Utiliser Math.LN2

La fonction suivante renvoie le logarithme en base 2 d'un nombre en utilisant la valeur de Math.LN2 :

js
function getLog2(x) {
  return Math.log(x) / Math.LN2;
}

getLog2(256); // 8

Spécifications

Specification
ECMAScript® 2025 Language Specification
# sec-math.ln2

Compatibilité des navigateurs

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
LN2

Legend

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

Full support
Full support

Voir aussi