Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What does !+ (not plus string) mean in JavaScript?

What does !+ (exclamation mark addition) mean in JavaScript?

Why is !+"000" true?
Why is !+"0010" false?

Tries:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

!+"000" // true
!+"00010" // false
!+"0a0" // true
!+"0,0" // true
!+[0,0,0] // true
!+[0,1,0] // true
true+"000" // true000

I’ve tried to search:

Here I saw the code: JS – Check if string contain only 0

This information is hard to find on the Internet.

>Solution :

+ is unary plus. It’ll convert the expression that follows to a number.

Then, ! negates the expression that follows: if it’s truthy, the result is false. If it’s falsey, the result is true.

A couple of examples:

!+"000"
!0 // because '000', when converted to a number, is 0
true

!+"00010"
!10 // because "00010", when converted to a number, is 10
false // because 10 is truthy

!+[0,1,0]
!NaN // because arrays can't be converted to numbers directly (usually)
true
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading