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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the operators that trigger type coercion?

A
    • :- String
    • :- Numbers
    • :- Number
  • / :- Number
  • > :- Number
How well did you know this?
1
Not at all
2
3
4
5
Perfectly