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

Why does 1 + 1 ? 1 : 0 + 1 return 1 instead of 3?

Why is 1 + 1 ? 1 : 0 + 1 equal to 1 and not 3? It’s correct that it returns if I wrap the expression 1 ? 1 : 0 with parentheses. But why is that needed? What is actually blocking the process to parse it correctly?

>Solution :

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

Because js first calculate 1 + 1 and after that check RESULT is true? if it is true, select 1.

1+1 is the truthy result

The falsy values in JavaScript are 0, 0n, null, undefined, false, NaN, and the empty string ""

enter image description here

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