javascript

Numbers


 

Numbers are primitive data types. It represents using numeric literals and support both integers and floating-point numbers.

 

1. Integers

Intergers are whole numbers (0, 1, 2, …) without any fractional or decimal parts.

 

Example:

// Intergers
let x = 1;
let y = 33234342543;

 

2. Floating Number

Floating-point numbers represent real numbers and are commonly used to handle values with fractional parts or very large/small values.  Significantly maximum 17 decimal digits of precision can be made in Javascript.
 

Example:

// float
let float1 = 5.2419; // With a decimal point
let float2 = 3.02e8; // Exponential notation
let float3 = 12e-4; // 0.0012
let float4 = 1 / 3; // 0.3333333333333333