18
rated 0 times
[
20]
[
2]
/ answers: 1 / hits: 5500
/ 10 Years ago, tue, april 8, 2014, 12:00:00
How does the below code execute?
if(a=2 && (b=8))
{
console.log(a)
}
OUTPUT
a=8
More From » operators
How does the below code execute?
if(a=2 && (b=8))
{
console.log(a)
}
OUTPUT
a=8
It has nothing to do with the if
statement, but:
if(a=2 && (b=8))
Here the last one, (b=8)
, actually returns 8 as assigning always returns the assigned value, so it's the same as writing
a = 2 && 8;
And 2 && 8
returns 8
, as 2 is truthy, so it's the same as writing a = 8
.