DEV Community

Oladotun Joseph
Oladotun Joseph

Posted on

VALUE TYPES IN JAVASCRIPT.

Values can be referred to as the fundamental building blocks of JavaScript programs as well as the atomic building blocks of JavaScript programs.Billions of pieces of data are processed inside of computers.Large amounts of data must be divided into several chunks for proper transmission, storage, and coordination. In the JavaScript environment, these different chunks are referred to as VALUES.
Despite the fact that all values are composed of bits, they can be divided into several VALUE TYPES according to the varied roles they play.The primitive value types in JavaScript are as follows:

  • Numbers

  • Strings

  • Booleans

  • Undefined values

NUMBERS

Values of the number type are numeric values including integers and floating-point numbers.
E.g;

let carNumber=50
let maleRatio=19.6

A single number value in Javascript is stored using 64 bits, hence there are only a finite number of alternative ways to express a number value. Only 10^Y decimal digits can be used to represent number value Y, and only 2^64 binary digits can be used to represent a single number value when given 64 binary digits, which is approximately 18 quintillion (an 18 with 18 zeros after it). However, not all whole numbers below 18 quintillion fit in a JavaScript number. Since such bits can also hold negative integers, one bit serves as a sign indicator. The requirement that non-whole numbers be represented is a significant problem.

To do this, the location of the decimal point is stored in part of the bits. The maximum whole number that can actually be kept is closer to 9 quadrillion (15 zeros), which is still quite huge.
It is assured that calculations using whole numbers less than 9 quadrillion will always be accurate. Calculations involving fractional numbers are, unfortunately, rarely accurate. Therefore, it is important to understand that digital decimal fractions are approximations and not precise numbers.
This takes us to three numbers in JavaScript known as "SPECIAL NUMBERS IN JAVASCRIPT," which are still regarded as numbers but don't operate in the same way as typical numbers. They are NaN, -infinity, and infinity. Although NaN is categorized in JavaScript as a number type value, NaN stands for Not a Number.

STRINGS

Strings, which are value types that are used to represent text data, are always enclosed in either single or double quotes.

E.g
const name = "My name is Jose"
const hobby = "Reading"

Although the "+" operator can be used on strings, strings cannot be divided, multiplied, or subtracted. Concatenation, or joining two strings together, takes the place of addition.

E.g
const a = "CON"
const b = "CAT"
const c = "ENA"
const d = "TION"
const e = a+b+c+d

console.log(e)= "CONCATENATION"<br>

BOOLEANS

This value type is used to represent values that are either TRUTHY OR FALSY.

E.g

Boolean example

UNDEFINED VALUES

The two values of this value type are UNDEFINED and NULL.They are used to indicate the absence of meaningful value.They are value themselves but do not carry any meaningful information.The undefined is the response triggered when operations that don’t produce any value,just have to yield some value.Although both UNDEFINED and NULL almost have the same meaning and can even be used interchangeably sometimes.There are two distinct differences between undefined and null which are;

  • undefined is often a default value automatically assigned by JavaScript, indicating the absence of an assigned value, while null is a value that can be explicitly assigned to indicate the intentional absence of an object value.

`let a;
console.log(a); // Output: undefined

let obj = null;
console.log(obj); // Output: null
`

  • Undefined is of type undefined, while null is of type object. null.

typeof(undefined)="undefined" while typeof(null)="object"

We now know about the four Javascript primitive value types and how they operate.

JavaScript#tecnhicalwriting

Top comments (0)