logic - Why does 2 && 3 results in 3 (javascript)? -


this question has answer here:

when type in browser's console:

console.log(2 && 3) 

it results second number (in case 3):

3 

can explain me why?

if left hand side of && evaluates false value, whole expression evaluates left hand side.

otherwise evaluates right hand side.

2 true value, 2 && 3 3.

for comparison, try console.log(0 && 1) , console.log(false && "something").


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -