Effective ActionScript: variable testing

Uncategorized, JavaScript, ActionScript, Front-End Programming — Matas Petrikas on March 28, 2007 at 2:01 pm
It’s a pretty usual ActionScript code excerpt:
 if (variable == true){ doSomething(); }
as you can see, the variable value is being tested here against its true value, which is a totally redundant action. A much more convenient style would be:
 if (variable){ doSomething(); }
What so nice about this solution, that it can check any variable types for valid values. Both following tests work identically :
 
var variable:Number = null;
if (variable){ doSomething(); }
 
var variable:String = undefined;
if (variable){ doSomething(); }

0 Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. | Matas Ideas and Thoughts