Type conversion is when we explicitly convert type to another.
const birthYear= "1991";
In order to be able to convert this string in to a number, in JS ,we have to do it with following function.
Now well define a variable with value a number:
const birthYear= 1991;
In order to convert a number to a string, we have to do it with the next function:
Type coercion it happens whenever an operator is dealing with two values that have different types, so than js will convert one type operation to match the other. As an example:
The next example is an important thing to remember in order to avoid bugs or confusions.
When we subtract string and numbers in one operation in JS, everything works fine. What do you think will happen when we’ll do the adding operation?
Type Boolean is truthy or falsy value. Total there are 5 types of falsy values.
Let’s see an example of falsy value.
and if to replace age with any number will come up with a truthy value
Happy coding !
scapsa0116 - Repositories
Student at FlatIron School Full Stack Software Developer. World traveler. - scapsa0116