2

I'm a bit confused by what is considered true in an if statement in javascript.

Example:

if (object.property) {
// stuff...
}

Under which circumstances will the content of this statement be executed? Are there any browser differences in interpreting this statement or anything else that you "need to know" regarding this?

For example: - property exists but is not set to anything - property is an empty string - property is null, undefined, false

Johan Dahl
  • 1,672
  • 3
  • 19
  • 35
  • 7
    There's a fantastic list of [Truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) and [Falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy) values over on MDN. – MTCoster Jan 27 '17 at 10:38
  • it will be `true` if the property exist and `false` if does not exists, exist and is 0 of if its empty. – Elmer Dantas Jan 27 '17 at 10:39
  • http://www.w3schools.com/js/js_booleans.asp – Jscti Jan 27 '17 at 10:39

0 Answers0