Hi, Operator precedence doesn't mean "evaluates before everything else", it means "in case of doubt, follow specified order".
Let's say you have the expression without parenthesis "A = B || C". There's a doubt as long as we don't know the precedence order between = and ||. Now "(A = B) || C". Since we know that () takes precedence over ||, we know that the expression is a || with two sides, A = B and C. And "A = (B || C)". Since we know that () takes precedence over =, we know that the expression is a = with left-hand A and right-hand B || C. Now "A || B = C". Let's say we don't know the precedence between || and =. Putting parenthesis "A || (B = C)", we know that we have a || with two sides, A and B = C. But || is still evaluated from left to right! On the contrary, (A || B) = C is invalid (wrong lef-hand side for assignment operator). Simply put, precedence has nothing to do with order of evaluation. 2011/11/7 Arian Stolwijk <[email protected]>: > From the ES5 specs: http://es5.github.com/#x11.11 > > The > production LogicalORExpression : LogicalORExpression || LogicalANDExpression is > evaluated as follows: > > Let lref be the result of evaluating LogicalORExpression. > > Let lval be GetValue(lref). > > If ToBoolean(lval) is true, return lval. > > Let rref be the result of evaluating LogicalANDExpression. > > Return GetValue(rref). > > So basically it is: Ok, we have a OR operator, with two sides: AExpr || > BExpr > Only if the boolean value of the evaluated value of AExpr is false, evaluate > the right hand side BExpr. > I replied with the bitwise operator just to illustrate the difference > between the logical and bitwise OR operators. > > On Mon, Nov 7, 2011 at 11:32 AM, HankyPanky <[email protected]> wrote: >> >> Arian, >> >> Thanks man for you reply, but bitwise operator isn't the case, I am >> specifically talking about logical OR. >> >> -- >> To view archived discussions from the original JSMentors Mailman list: >> http://www.mail-archive.com/[email protected]/ >> >> To search via a non-Google archive, visit here: >> http://www.mail-archive.com/[email protected]/ >> >> To unsubscribe from this group, send email to >> [email protected] > > -- > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/[email protected]/ > > To search via a non-Google archive, visit here: > http://www.mail-archive.com/[email protected]/ > > To unsubscribe from this group, send email to > [email protected] > -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
