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?
2 comments
Log in to join the discussion
Log In2 Comments
palmer.zara2d ago
Classic JavaScript, always making things weird.
1
taylor822d 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