I researched a lot and found out that comma
inside an if statement is :
In the C and C++ programming languages, the comma operator (represented by the token ,) is a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value (and type).
and in javascript is something like C
and C++
But still it is unclear to me, I can't get it why should I use some statements like these :
int a = 1, b = 0;
if(a, b) // it is `false` because b is 0 --> if(0)
if(b, a) // it is `true` because a is 1 --> if(1)
Or in a better example:
var number = 10;
console.log(someFunc(number));
function someFunc(number){
return !(0, isNaN(number));
}
// this results true. 0 is discarded and isNaN(10) is false so !(false) -> true
What is the point of using 0
and ,
inside return condition ?
This is another link others mentions but they didn't really answered the question. When is the comma operator useful?