True Plus Ture in JavaScript?



True Plus Ture in JavaScript?

True Plus Ture in JavaScript?

I asked a question in community tab. It was: What’s the output of console log true + true. Options were true, 1, error and 2. It received 47 votes/answers. Most people selected true. But the answer is 2.

true + true equals 2 in javascript. Let me explain how. In JavaScript, when you try to perform arithmetic operations with non-numeric values, the language attempts to implicitly convert the non-numeric values into numbers before performing the operation. This is called type coercion.

When you have an expression like true + true, JavaScript converts the true values into their numeric equivalents. In this case, true is converted to the number 1. So the expression becomes 1 + 1, which equals 2.

For the expression true + true + 1, the same type coercion happens. The true values are converted to 1. So the expression becomes 1 + 1 + 1, which equals 3.

Our tutorials help you to improve your career growth, perform better in your job and make money online as a freelancer. Learn the skills to build and design professional websites, and create dynamic and interactive web applications using JavaScript, or WordPress. Our tutorials are tailored to help beginners and professionals alike. Whether you’re just starting in the field or you’re looking to expand your knowledge, we’ve got something for you. Join us on this journey to becoming a skilled web developer. Subscribe to our channel and let’s get started!

Thank You!
👍 LIKE VIDEO
👊 SUBSCRIBE
🔔 PRESS BELL ICON
✍️ COMMENT

⚡Channel: https://www.youtube.com/@webstylepress
⚡Website: https://www.webstylepress.com
⚡FaceBook: https://www.facebook.com/webstylepress
⚡Twitter: https://twitter.com/webstylepress
⚡GitHub: https://github.com/webstylepress
#js #javascript #WebStylePress