Two lines. Same numbers. Completely different outputs 🤯 👉 "console.log(1 + 2 + "3");" 👉 "console.log("1" + 2 + 3);" Looks simple… but JavaScript has its own way of thinking 👀 Are you sure you know what the output will be? Watch till the end to understand how JavaScript actually evaluates expressions and why order matters more than you think! #JavaScript #WebDevelopment #Coding #Frontend #Developers #JSBasics
This really highlights how those subtle JavaScript behaviors can catch us off guard, even when we think we've got it all figured out.
1.) "33" - The first two numbers are added normally (1 + 2 = 3). Then the next value is a string, JavaScript performs concatenation joining the number 3 and the string "3" to get "33". 2.) "123" - Since the first value is a string the + operator immediately switches to concatenation mode. It joins "1" and 2 to make "12", then joins "12" and 3 to result in "123".