JavaScript: Understanding Data Types and Basic Operations

😄 JavaScript has a way of testing your thinking. 2 + 2 = 4 🙂 "2" + "2" = "22" 🤔 2 + 2 - 2 = 2 😎 "2" + "2" - "2" = 20 🤯 JavaScript isn’t illogical — it simply follows rules we often overlook. ✔️ + may join values instead of adding them ✔️ - always converts values to numbers ✔️ Data types quietly control the outcome Memes make it relatable. Strong fundamentals make it understandable. JavaScript isn’t hard. Ignoring the basics makes it feel that way. 😉 #JavaScript #WebDevelopment #Frontend #ProgrammingHumor #CodingLife #LearnJavaScript

  • No alternative text description for this image

For "2" + "2" , JS does type string concatenation instead which evaluates to "22" For "2" + "2" - "2" , first "2" + "2" is evaluated which is "22" (concatenation). Then it becomes "22" - "2". For minus operator, if the operands are a string, JS does type coercion which then evaluates to 22 - 2 = 20

JavaScript is quirky but predictable — mastering type coercion and operator behavior is key to thinking like a JS developer.

Like
Reply

So what ? Its logically correct

See more comments

To view or add a comment, sign in

Explore content categories