function rrr() {
return (1,2,4);
}
n= rrr();
console.log(n);
when running this code I got the output 3,but I expected 1,2,3 as an output someone please explain this why the output is last element 3 instead of (1,2,3)?
function rrr() {
return (1,2,4);
}
n= rrr();
console.log(n);
when running this code I got the output 3,but I expected 1,2,3 as an output someone please explain this why the output is last element 3 instead of (1,2,3)?
Comma
operator in JavaScript combines multiple expressions, evaluates the expressions from left to right, and returns the value of farther right expression.
Due to the same reason, let x = (1,2,3);
assigns value 3
to variable x
, let y = (1,2,5-1)
assigns value 4
to variable y
.