"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Exploring the Core of true value vs false value in JavaScript...

Exploring the Core of true value vs false value in JavaScript...

Published on 2024-11-08
Browse:299

In JavaScript, a truthy value is any value that is considered true when evaluated in a Boolean context. Values that are not falsy are considered truthy.

Example of truthy values:

  • Any non-zero number (1,-5,3.14)
  • Non-empty strings ("hello" )
  • space value(" ")
  • Objects ({}, [])
  • The boolean true

Now Example,

1.Checking a Non-empty String
Exploring the Core of true value vs false value in JavaScript...

  • Explanation: The string "JavaScript" is a non-empty string, so it evaluates to true.

1.Checking a String with a Space

Exploring the Core of true value vs false value in JavaScript...

  • Explanation: The string " " (a string containing a space) is also a non-empty string, which evaluates to true.
Release Statement This article is reproduced at: https://dev.to/tanvir_ahmed_286/exploring-the-core-of-true-value-vs-false-value-in-javascript-40p?1 If there is any infringement, please contact [email protected] delete
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3