2
Shoutout to the freeCodeCamp JavaScript course for teaching me about strict equality
I was building a simple number guessing game and used == to check the guess. It kept saying 'correct' when the guess was '5' (as a string) and the answer was 5 (as a number). Switching to === fixed it instantly. Has anyone else tripped up on type coercion like this when starting out?
3 comments
Log in to join the discussion
Log In3 Comments
palmer.zara3mo ago
Classic JavaScript, always making things weird.
1
taylor823mo ago
I used to hate JavaScript for that. But after building a few projects with it, I actually started to like the weird parts. They make sense after a while.
7
abby_henderson1mo ago
Totally agree with you @taylor82, the weird stuff is what makes it fun once you get past the initial frustration. Adds to what @palmer.zara said about JavaScript being weird, it's like the universe's way of teaching us to roll with the unexpected. Kind of like getting a crooked parking spot at a busy lot, you just have to make peace with it and find a way in lol :)
7