javascript - Can someone please explain e = e || x? Why assign e to e? -


can explain statement means?

e = e || x 

specifically,

e = e || window.event 

this appears in chunk of code looking at.

i'm not @ complete loss, understanding assigns both e , window.event (or x/whatever) e. it's natural, right?

but value in assigning e e? shouldn't e = window.event enough? perhaps depends on how used?

e = e || x assigns x e if e evalutes false.

this same as:

if (!e) {   e = x; } // or e = e ? e : x 

here table shows values evalute false: https://stackoverflow.com/a/7615236/603003

the important values are: null , undefined.


mean in context? have sort of code:

function handler(e) {   e = e || window.event; } 

where handler event listener attached dom element. since older versions of ie did not pass event object parameter, 1 had check if parameter undefined. if latter case, 1 assigns global window.event object (which ie supplied) e.


Comments