Jump to content

((


Drycodez

Recommended Posts

None is required. You sometimes see that in conditions when multiple expressions are joined with && or ||, as here, to make it more readable. I see no use in surrounding a return value with (), but maybe some developers find it makes the expression more readable. Maybe it's required in other languages and they do it from force of habit?

Link to comment
Share on other sites

The parens in the condition are just a way to group statements. Sometimes, when and expression could be ambiguous, they are required (EDIT: That is, required in order to achieve expected results). Usually, though, it is just a matter of readability.This:if ((A==1)&&(B==2))is easier to read than:if (A==1&&B==2)because it clearly separates each condition that must be checked.As for the parens around true, I don't think there really is a purpose. Developer habit?Though it seems like it should return a boolean object (rather than a plain boolean value), similar to the way that ("a string").substr(2) works...

Link to comment
Share on other sites

Consider this:if (A == 1 && B == 2 || C == 3)You would probably want to explicitly group those so it's obvious whether you mean this:if ((A == 1 && B == 2) || C == 3)or this:if (A == 1 && (B == 2 || C == 3))And no, parentheses are not a replacement for curly brackets.

Link to comment
Share on other sites

Group?
{document.write('A'); alert('B');}

the curly braces group the above statement 2geda! Does it mean dat ( and ) can do thesame?

that would only work in the context of function scope, there's a big difference for why and when the two are used (parens vs. braces). the parenthesis in the original context are just conveniences founded on the simple rules of order of operations; aka PEMDAS - parenthesis, exponents, multiplication, division, addition, subtraction.
Link to comment
Share on other sites

Consider this:if (A == 1 && B == 2 || C == 3)You would probably want to explicitly group those so it's obvious whether you mean this:if ((A == 1 && B == 2) || C == 3)or this:if (A == 1 && (B == 2 || C == 3))
So I know I've got this right:The order of operations here goes from left to right, correct? So without parens, you would get the same behavior as this:if ((A == 1 && B == 2) || C == 3)Or is it the other way around?
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...