11 September 2013
var myElement = document.getElementById('id');
// some statements here
Here are the five falsy values:
All other values are truthy, including the string ‘false’ and all objects.
In the above example,
myElement will be
null if an element with that id is not found, and it will be an object if it finds one. The above if works because
null is a falsy value, while
object is a truthy value.