-
Notifications
You must be signed in to change notification settings - Fork 885
Description
Coercion and Abstract operations in Javascript.
Proposed title of the article
How coercion works behind the scenes
Proposed article introduction
You must have experienced a case where people are trying to bash Javascript by showing how bizarre it is while surfing the internet. This is one of the cases that you must have found :
console.log(""==[])
// this returns trueAnd you see, "Weird" is a short-lived term unless you comprehend how it's actually working. This is one of the cases where if you don't understand coercion, this will seem a like a bug in JS. Therefore, understanding coercion in JavaScript properly is important because not only it will help new developers to write better and understandable code, but it will also help other developers to avoid bugs that can occur due to not understanding coercion.
In this article, I will explain how coercion works in JavaScript and how it works behind the scenes. We will also have a look at abstract operations, which is the core concept behind coercion.
Key takeaways
At the end of this article, readers would be able to:
- Readers will know what coercion in Javascript is.
- Reader will know what abstract operations are.
- Reader will know how coercion works under the hood.
Conclusion
In this article, we leaned what coercion is and how it works under the hood using abstract operations. We also saw implicit versus explicit typecasting and learned about the concept of boxing in Javascript.
Javascript being a beginner-friendly language comes with its caveat around typecasting, therefore it is important to know all these concepts to avoid these caveats as this will help you avoid bugs in your code and your coercion to your advantage instead of avoid it.