DEV Community

Cover image for Coercion in JavaScript.

Coercion in JavaScript.

Uddesh on March 22, 2019

JavaScript is strange, It has got lots of unexpected behaviors and coercion is one of them. Coercion is always a subject of argument among the comm...
Collapse
 
susickypavel profile image
Pavel Susicky • Edited

Cool post, Uddesh!

I have a note on this paragraph.

console.log('100' === 100) // False

In the case of triple equal, the result will be False because triple equal operator strictly checks the type of left and right side.

In fact, we can say that triple equal checks value with coercion "disabled". On the other hand double equal allows coercion.

Collapse
 
uddeshjain profile image
Uddesh

Yes, This also can be a case but as far as I concerned triple equal checks the type of the value of left and right side.

Collapse
 
azarouamine profile image
AzarouAmine • Edited

The triple equal checks both the value and the type, so in this example's case, the values are equal but the types aren't, so the output is false (false(type) & true(value) => 0 & 1 == 0 => false).

Collapse
 
itenev profile image
Ивелин Тенев

The result of '100'+10 is '10010' as you've stated in the previous sentence, not 110.

Collapse
 
uddeshjain profile image
Uddesh

Thanks a lot for pointing out, Fixed now.