Archi's Academy

GetStarted

GetStarted
Get in touch

Software Development

Coding

The three most commonly used primitive data types in Javascript are number, string, and boolean. At one point or another, we may run into situations where we would like to carry out an operation but the available values are of different types.

For instance, we may prompt a user’s birth year and receive it as a string, but to calculate their age, the input string has to be converted into a number. This is where type conversion comes in.

Type conversion refers to the manual conversion of a value from one type to another.

Javascript methods for performing type conversion between strings and numbers are:

Number() - converts a string to a number

String() - converts a number to a string

To convert strings and numbers to Boolean values, Boolean() is used. It results in either true or false. There are 5 values that when converted to boolean become false: 0, an empty string(‘ ‘), undefined, NULL, and NaN. They are referred to as falsy values. Everything else is a truthy value and will become true when converted to a boolean, including an empty object.

It is worth noting that the methods start with capital letters.

Archis-frontend-developer-trainee

Victor Muya

Tuesday, Jun 29, 2021