Skip to content

Instantly share code, notes, and snippets.

@usametov
Created August 22, 2018 14:34
Show Gist options
  • Save usametov/ec662ae354e63d395809860c7ae38b0b to your computer and use it in GitHub Desktop.
Save usametov/ec662ae354e63d395809860c7ae38b0b to your computer and use it in GitHub Desktop.
5 + 5
You can tell me what this is, right? It’s 10, that’s right.
What about this?
5 + '5'
This is '55'. Makes sense, right?
'5' + 5
This is also '55'. This makes more sense than the last one, though, even though it still makes no sense.
5 + +'5'
Now what’s this? This is 10 again.
'5' - - '5'
This is also 10.
NaN === NaN
This is false.
{} + [] === 0
[] + [] === ''
[] * 1 === 0
false + 1 === 1
These are all true.
typeof NaN === 'number'
true! JavaScript, you’ve been exposed.
This is just what I can think of off the top of my head. JavaScript can be so confusing. It’s not just type juggling you have to worry about. Also, speaking of type juggling:
5 == '5'
[] == ''
({}) == '[object Object]'
true. This is why you should always use ===. == is just plain useless, I assure you. I don’t know why it exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment