Javascript && Evaluate

here is the javascript code:

var test = { "h" : function (a) {return a;}, "say" : "hello" }; 

First start:

 test['h'] && true 

the result is correct

second run:

 true && test['h'] 
Result

is the function ()

my question is why the first launch and second launch give an excellent result

+4
source share
1 answer

The last true argument && returned. (If there is an argument without truth, of course, false is returned). This just works && .

+5
source

Source: https://habr.com/ru/post/1398740/


All Articles