DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Sai gowtham
Sai gowtham

Posted on

JavaScript Quiz Part 3

If you miss the part 1 and part 2 check out part1,part2

  1. [ ]+{ }

  2. [ ]+0

  3. { }+1

  4. [ ]-0

Top comments (8)

Collapse
 
arne_mertz profile image
Arne Mertz

WAT

That's all there is to say about those things... See this brilliant talk:

destroyallsoftware.com/talks/wat

Collapse
 
kip13 profile image
kip • Edited on

Try with this too:

  • [1] - 0
  • [1] + 1
  • [1] - 1
  • [1, 2] - 0
  • 1 + {}
  • [1] + {}
Collapse
 
droidmakk profile image
Afroze Kabeer Khan. M
  1. I Suspected but got wrong.
  2. I got it right
  3. Never expected that to happen
  4. Obviously i expected
Collapse
 
antoine_m profile image
Antoine Mesnil

Wrong on the first one, definitly not expected that.

Collapse
 
antogarand profile image
Antony Garand

How about []+{} == {}+[]?

Collapse
 
val_baca profile image
Valentin Baca

My answers, 50%:

  1. [{}] // Wrong
  2. [0] // Wrong
  3. 1 // Right
  4. 0 // Right
Collapse
 
chiragshah1309 profile image
Chirag Shah

How does this happen? Can anyone explain? :O

Collapse
 
antogarand profile image
Antony Garand

The + operator can either concatenate two elements or perform an addition.

In the first case, it will convert both elements to strings, the array being an empty string and the second one being [Object object].

Second does pretty much the same thing, [] = '', 0 = '0', '' + '0' = '0'
And the others are similar.

12 APIs That You Will Love

>> Check out this classic DEV post <<