…and (+””) equals zero…

In the parent post, someone asked: ‘What is this (+””)?’

Image for post
Image for post

How does this work? The unary plus operator tries to convert its operand to a number. An empty string is a falsey value in JavaScript so it converts it to 0. For more information on type conversion in JavaScript, I recommend Dave Herman’s .

Written by

If you point your cart north, when you want to go south, how will you arrive?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store