Feb 11th, 2011 In general it's a good practice to check for the existence of something before blindly using it by faith and hoping it works. There are various times during the execution of scripts when a variable may not be defined, it may be null, or it might be an empty string. These are three things that are easily conflated. A good way to look at this is thinking of these as having increasing levels of existence (getting a bit philosophical here for a moment…): foo0; // existence level 0 (creates the error "not defined") var foo1;
Read full article from Checking for undefined, null, and empty variables in JavaScript | David Calhoun's blog
No comments:
Post a Comment