JavaScript Numbers



JavaScript Numbers

  • JavaScript has only one type of number. Numbers can be written with or without decimals.
let x = 1.5;    // A number with decimals
let y = 1;       // A number without decimals
javascript-number

Sample Code

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>Numbers can be written with or without decimals:</p>

<p id="demo"></p>

<script>
let x = 1.5;
let y = 1;
document.getElementById("demo").innerHTML = x + "<br>" + y;
</script>

</body>
</html>

Output

Numbers can be written with or without decimals:
1.5
1

Extra large or extra small numbers

  • Extra large or extra small numbers can be written with scientific (exponent) notation.

Sample Code

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>Extra large or extra small numbers can be written with scientific (exponent) notation:</p>

<p id="demo"></p>

<script>
let x = 123e5;
let y = 123e-5;
document.getElementById("demo").innerHTML = x + "<br>" + y;
</script>

</body>
</html>

Output

JavaScript Numbers
Extra large or extra small numbers can be written with scientific (exponent) notation:
12300000
0.00123

Related Searches to JavaScript Numbers