JS Standard Protection:
if (!x) { // throw error }
!x will catch any undefined , null , false , 0 or an empty string.
If you want to check if the value is valid, you can do this:
if (Boolean(x)) {
In this fragment, a block is executed if x is nothing but undefined , null , false , 0 or an empty string.
-tjw
Travis webb
source share