You have to understand that expressions that are connected with a logical AND (&&
) only evalute until the first expression evaluates to false (or is falsy). So, the following piece of code means:
- evaluate expr1
if (expr1): evaluate expr2
expr1 && expr2;
In your case expr1
is the index i
, which means, that your code translates to something like this:
if (i) {
tabMap['tab' + i].left = 'tab' + (i - 1);
}
This if condition will evalute to true if i
is greater then zero. So, what the if condition should look like is:
if (i > 0) {
tabMap['tab' + i].left = 'tab' + (i - 1);
}
The same goes for your second statement.
I personally find not good practice at all to hide the meaning of your code by doing clever things like expr1 && expr2
. If you want to do something if the index is greater then zero, then you should write it that way. I know you didn't write the code but I just had the urge to say that.