| bo's profileAmosPhotosBlogLists | Help |
|
April 15 [thelist] What's the most reliable way to check a javascript null?If you really want to check for null, do:<br /><br /> if (null == yourvar) // with casting<br /> if (null === yourvar) // without casting<br /><br /><br />If you want to check if a variable exist<br /><br /> if (typeof yourvar != 'undefined') // Any scope<br /> if (window['varname'] != undefined) // Global scope<br /> if (window['varname'] != void 0) // Old browsers<br /><br /><br />If you know the variable exists but don't know if there's any value<br />stored in it:<br /><br /> if (undefined != yourvar)<br /> if (void 0 != yourvar) // for older browsers<br /><br /><br />If you want to know if a member exists independent of whether it has<br />been assigned a value or not:<br /><br /> if ('membername' in object) // With inheritance<br /> if (object.hasOwnProperty('membername')) // Without inheritance<br /><br /><br />If you want to to know whether a variable autocasts to true:<br /><br /> if(variablename)<br />TrackbacksThe trackback URL for this entry is: http://amos1975.spaces.live.com/blog/cns!E3F1D5045734C6F9!262.trak Weblogs that reference this entry
|
|
|