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
Post a Comment