NUMBERS IN JAVASCRIPT

JS

Number with the ES2019 specification is the only type associated with numbers. We do not have the float type for decimal numbers. Numbers in javascript are represented according to the IEEE 754 floating point 64-bit standard. Every number even integers are represented and stored in memory as 64-bit floating point numbers.

IEEE 754

THE SCIENTIFIC OR EXPONENTIAL NOTATION

Any number can be represented with scientific notation (also called exponential):

mantissa*base exponent

The mantissa are the significant figures, excluding zero; the base is ten because we are in the decimal system. For example, a number we can represent it as (figure below):

IEEE 754

We see that the comma fluctuates, as the exponent increases it moves from right to left, while as the exponent decreases it moves from left to right.

IEEE 754

Let’s take one more example.

IEEE 754

The normalized scientific form requires that there be a number before the root point that is not zero. The floating point standard for storing numbers transforms them into the normalized scientific notation.

IEEE 754

THE IEEE 754 STANDARD

IEEE 754

If the sign bit is zero then the number is positive, otherwise negative. As much as 52 bits is a lot to represent the mantissa,
there are cases where they may not be enough, and it is not just a problem for large numbers.

console


Let’s start by saying that this is not a problem with javascript but with the IEEE 754 standard
. 0.110 is a periodic binary number that repeats infinitely, so it must be rounded, kind of like we do with decimal numbers .

rappresentazione di 0.1
IEEE 754

As small as the difference is, effectively we cannot say that the two numbers are the same. Problems occur with very large or very small numbers. With this system we can represent exactly the numbers in the range -(253 -1) and + (253 -1).

Oggetto number
Copy to Clipboard

THE BIGINT TYPE.

The BigInt type represents integers. We can do all the arithmetic operations we want, it can also represent very large numbers that go far beyond the constant MAX_SAFE_INTEGER thus exceeding the limits of type Number.

Copy to Clipboard

TYPE BOOLEAN

Boolean represents a logical entity and can have two values: true and false. For example, in JavaScript, Boolean conditional tests are often used to decide which sections of code to execute (such as if statements) or repeat (such as for loops).

NULL VS UNDEFINED

Null means no value, undefined indicates that a variable, object or function has been declared but not defined. Using the operator !! both return false, plus both are primitive data.

Copy to Clipboard
Copy to Clipboard

LINKS TO PREVIOUS POSTS

THE JAVASCRIPT LANGUAGE

LINK TO CODE ON GITHUB

GITHUB