javascript - var foo = foo || alert(foo); -


can explain does?

var foo = foo || alert(foo); 

if foo defined , evaluates true, sets foo = foo, i.e. nothing.

if foo defined evaluates false, popup whatever foo (false, null, undefined, empty string, 0, nan), since alert returns nothing, foo set undefined.

if foo not yet defined, exception thrown. (edit: in example, foo defined because of var foo declaration.)


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -