Type Conversion & Coercion Flashcards
1
Q
What is Type conversion in JS?
A
Type conversion is manually converting from one type to another.
JavaScript can convert to a number, String and to a boolean but cannot convert a String to int.
Example:
const Year = '1991' console.log(Number(Year)
2
Q
What is type coercion in JS?
A
This is done automatically by JS, when two values have different types.
Example:
- console.log(‘I am’ + 22 + ‘Years old’);
//Returns ‘I am 22 years old’
3
Q
What are the operators that trigger type coercion?
A
- :- String
- :- Numbers
- :- Number
- / :- Number
- > :- Number