Web Development

JavaScript Boolean

JavaScript Boolean  is section 8 of Beginner’s Guide to JavaScript.

Very often, in programming, you will need a data type that can only have one of two values. We called it as binary values.

  • YES / NO
  • ON / OFF
  • TRUE / FALSE
  • 0 / 1

A JavaScript Boolean represents one of two values: true or false.

The Boolean() Function

You can use the Boolean() function to find out if an expression (or a variable) is true.

Boolean(20 > 19)        // returns true

(20 > 19)              // also returns true
20 > 19                // also returns true

 

Boolean is mostly related with comparison operators and conditional statements. The Boolean value of an expression is the fundamental for JavaScript comparisons and conditions.

Everything with a Real Value is True. 

  • 100
  • 3.14
  • -15
  • “Hello”    ———–    Any (not empty) string is true
  • “false”   ———–    Even the string ‘false’ is true
  • 7 + 1 + 3.14 Any expression is (exept zero) is true

Everything Without a Real Value is False

  • The Boolean value of 0 (zero) is false. 
  • The Boolean value of -0 (minus zero) is false. 
  • The Boolean value of “” (empty string) is false.
  • The Boolean value of undefined is false.
  • The Boolean value of null is false.
  • The Boolean value of false is (you guessed it) false.
  • The Boolean value of NaN is false.

 


What’s Next?

Learn what includes in JavaScript Math

 

 

Join Our Newsletter Today

Stay updated with all latest updates.
Give it a try, you can unsubscribe anytime.
Subscribe
SUBSCRIBE NOW

About the author

Sandeep Likhar

Sandeep Likhar from Indore India, Blogger, eBook Designer and Founder of LetsDnD. Having five years of experience in industry as a Digital Publishing Expert and eBook Converter providing services to Authors, Publishers and distributors worldwide. Proficient in converting books into various formats HTML, epub, mobi, word, PDF including all major online platforms iTunes, Kobo, Kindle, Createspace, B&N, Smashwords and more.

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz
DON’T MISS OUT!
Subscribe To Newsletter
Be the first to get latest updates and exclusive content straight to your email inbox.
Stay Updated
Give it a try, you can unsubscribe anytime.

Join Our Newsletter Today

Stay updated with all latest updates.
Give it a try, you can unsubscribe anytime.
Subscribe
SUBSCRIBE NOW