JavaScript Operator Precedence

时间:2017-08-30 20:29:44

标签: javascript

According to Mozilla, the === operator has higher precedence than the || operator, which is what I would expect.

However this statement evaluates to the number 1, rather than false.

DisplayInternalUI

You have to wrap in parens to get a boolean:

<MsiPackage SourceFile = 'xxx' Id='xxx' Vital='yes'  DisplayInternalUI='yes'></MsiPackage>

What gives?

NOTE this is not a dup of this question, which does not have anything about equality operators - JavaScript OR (||) variable assignment explanation

2 个答案:

答案 0 :(得分:4)

Higher operator precedence is like a parenthesis around the operands.

- (void)collectionView:(UICollectionView *)collectionView 
didSelectItemAtIndexPath:(NSIndexPath *)indexPath

The second part gets never evaluated, because of the truthy value of - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { selectedRecipeImageName = [recipeImages[indexPath.section] objectAtIndex:indexPath.row]; ... [self.collectionView deselectItemAtIndexPath:indexPath animated:NO]; } .

答案 1 :(得分:4)

%40 is a short circuit operator and conditions are evaluated from left to right.
So here : %, if the %25 condition is ||, the whole condition is evaluated to left || right and the left one is never evaluated.

Here :

true

true assigns right to let x = 1 || 0 === 0; // x === 1; and the second condition after x = 1 is never evaluated as 1 is x to ||.

And here :

if (1)

evaluated is evaluated to true as let x = (1 || 0) === 0; // x === false; is still (1 || 0) to true.
And then if (1) is evaluated to evaluated.
So true is valued to true === 0.