views:

792

answers:

2

This runs in as3, and javascript. Why? I know how && and || work, but a list? is this as3 specific? Is this in other languages? I'm a mouth breathing PHP/AS2 programmer. Or did everyone already know this and I'm a tool for not reading documentation properly?

AS3

if (true, true, true) {
     trace("true?")
}//result - "true?" traced

Javascript

if (true, true, true) {
    alert("true?")
}//result - "true?" alert message popped up

if(false, false, false){
     alert("true?")
 }
 else{alert("false")}
 //result - "false" alert message popped up

if(true, false, false){
    alert("true?")
}
else{
    alert("false")
}
 //result - "false" alert message popped up
+3  A: 

I presume javascript has a comma operator like C, which takes multiple arguments and returns the last one. It's typically used to for loops where you want to initialize more than one value:

for(i=0, j=0; j< 10; j++) {
...
}

le dorfier
A: 

The comma is used to evaluate expressions in a sequence, the same thing could be done with parenthesis groups separated by &&

Theo.T
I think this is wrong. Evealuating in a sequence can either return the value of the first expression, the value of the last expression, all values ORed together or ANDed together. I think it returns the last expression as the first answers says.
ordnungswidrig