4

This runs in ActionScript 3 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
Assembler
  • 794
  • 1
  • 8
  • 24
  • Possible duplicate of [What does a comma do in JavaScript expressions?](http://stackoverflow.com/questions/3561043/what-does-a-comma-do-in-javascript-expressions) –  Jan 27 '16 at 21:47

2 Answers2

4

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++) {  
...   
}
Jason Plank
  • 2,336
  • 5
  • 31
  • 40
dkretz
  • 37,399
  • 13
  • 80
  • 138
0

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

Theo.T
  • 8,905
  • 3
  • 24
  • 38
  • 1
    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 Apr 20 '09 at 11:52