Changes between Version 15 and Version 16 of Coding_Conventions


Ignore:
Timestamp:
Mar 5, 2012, 12:31:57 AM (12 years ago)
Author:
historic_bruno
Comment:

Some info about JS undefined vs. null

Legend:

Unmodified
Added
Removed
Modified
  • Coding_Conventions

    v15 v16  
    249249}}}
    250250
     251 * To test if a property or variable is undefined, use explicit type+value equality (`===`), instead of value equality (`==`) or `typeof()`:
     252{{{
     253#!js
     254if (someObject.foo === undefined)
     255  // foo is not defined
     256else
     257  // foo is defined
     258}}}
     259 * In general you don't want to explicitly check for `null` which has a distinct, often misunderstood, meaning from `undefined`. A few parts of the engine return a `null` object reference (for example, the component system when a component is not available for the specified entity, or the GUI when a requested object was not found), you can check for valid object references easily:
     260{{{
     261#!js
     262if (!cmpFoo)
     263  // Oh it's not a valid component, don't use it
     264else
     265  // It is a valid component, we can use it
     266}}}
     267
    251268== XML ==
    252269