-1

So I was on a site and I was peeking into the source code, and all the JavaScript code was obfuscated(as usual). I don't know what obfuscated code would be normally, but I think its like this:

var1 > 10 / 2, var1 = 0

is the same as

if(var1 > 10 / 2){
    var1 = 0;
}

is this how it is? If not, please tell.

MasterPtato
  • 129
  • 2
  • 9
  • 1
    No those are not the same. https://www.google.com/search?q=what+is+obfuscated+code –  Nov 05 '16 at 17:29
  • 1
    No. This is using the comma operator, so both of these will be evaluated but only the second one will be returned. This must be a part of a larger thing you are not showing because right now it's rather meaningless as it resolves to `var1 > 10 / 2; var1 = 0`. – VLAZ Nov 05 '16 at 17:29

1 Answers1

2

You can see what happen, when you place the code inside of some parenthesis inside of console.log. You need some extra parenthesis, because console.log reads the comma as separator for parameter.

Comma Operator:

The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand.

var var1;
console.log(var1);                      // undefined
console.log((var1 > 10 / 2, var1 = 0)); // 0
console.log(var1);                      // 0
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392