Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What are the rules for determine the "truth" of any value not already of the Boolean type?

user-image
Question added by Saadia Idris , Employee , Jazz Company
Date Posted: 2017/10/25
Ahmed Samir
by Ahmed Samir , Web Developer , Raqy Company for Electronic Trading

  1. If the value is a number, it is false if exactly equal to zero and true otherwise.
  2. If the value is a string, it is false if the string is empty (has zero characters) or is the string "0", and is true otherwise.
  3. Values of type NULL are always false.
  4. If the value is an array, it is false if it contains no other values, and it is true otherwise. For an object, containing a value means having a member variable that has been assigned a value.
  5. Valid resources are true (although some functions that return resources when they are successful will return FALSE when unsuccessful).
  6. Don't use double as Booleans. 

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.