JavaScript Quiz Part 3

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

  1. [ ]+{ }

  2. [ ]+0

  3. { }+1

  4. [ ]-0

Did you find this post useful? Show some love!
DISCUSSION (8)

WAT

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

destroyallsoftware.com/talks/wat

Try with this too:

  • [1] - 0
  • [1] + 1
  • [1] - 1
  • [1, 2] - 0
  • 1 + {}
  • [1] + {}
  1. I Suspected but got wrong.
  2. I got it right
  3. Never expected that to happen
  4. Obviously i expected

Wrong on the first one, definitly not expected that.

My answers, 50%:

  1. [{}] // Wrong
  2. [0] // Wrong
  3. 1 // Right
  4. 0 // Right

How does this happen? Can anyone explain? :O

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.

Classic DEV Post from Jan 30

Describe the worst coding culture you've been a part of

There are a lot of ways to have bad culture, and coding is sometimes the least ...

READ POST
Follow @ben to see more of their posts in your feed.
Sai gowtham
JavaScript developer, Writer & Serverless
More from @saigowthamr
Binary search algorithm in javascript
#discuss #javascript #computerscience
Intro to Logarithms Big O
#computerscience #javascript #webdev #beginners
Trending on dev.to
Lets Build Web Components! Part 4: Polymer Library
#webcomponents #customelements #polymer #javascript
Optimistic Offline-First Apps With Vuex
#pwa #webdev #javascript #vue
CSS Specificity and the use of !important: a case study
#webdev #css #beginners #tutorial
JAMstack. How sites are becoming even faster in a bloated web.
#javascript #jamstack #dev #webdev
The best automated deployment tool is… the one that fits your needs
#webdev #devops #tips
Challenge: CSS Navigation
#challenge #beginners #fun
User Authentication with Express.js
#dev #beginners #javascript
Beginner Node.js tutorial #1
#node #javascript #tutorials #beginners