Reputation: 1414
here is javascript code:
var test = {
"h" : function (a) {return a;},
"say" : "hello"
};
First run:
test['h'] && true
result is true
second run :
true && test['h']
result is function()
my question is, why first run and second run produce different result
Upvotes: 4
Views: 118
Reputation: 5650
The last truthy argument of &&
is returned. (If there is a non-truthy argument, false is returned, of course.) That's just how &&
works.
Upvotes: 5