Understanding Javascript The Weird Part Parts [2021] Guide

for (var i = 0; i < 3; i++) setTimeout(() => console.log(i), 100);

Understanding the "weird parts" transforms you from a developer who copies code from Stack Overflow into a developer who engineers robust solutions. When you understand coercion , you control your data types. When you understand hoisting , you control your scope. When you understand this , you control your context. understanding javascript the weird part parts

Always use strict equality ( === ) to avoid unexpected type conversion. It checks both value and type, saving you hours of debugging. for (var i = 0; i &lt; 3; i++) setTimeout(() =&gt; console

JavaScript is , meaning it tries to be helpful by converting types on the fly. This is called Coercion . The "weird" part is how it handles comparisons: 3 == "3" is true (String is coerced to a number). false == 0 is true . "" == 0 is true . When you understand this , you control your context