Javascript - Type coercion
📖 Read the lesson
Code Life
By Pierre Marsaa
What is Type Coercion?
JavaScript has a special feature called
type coercion
. It means JavaScript can automatically convert one data type to another when needed.
For example, when you try to compare a string with a number, JavaScript will try to convert one of them so the comparison makes sense:
↗️
Loading editor...
↶
▶️ Run
↷
Type coercion can be helpful, but it can also lead to unexpected results if you're not careful! That's why understanding how it works is important.
Verify