Title is most of the question, what allows this to be valid code? Is there any benefit or trick that would allow me to utilize this?
Asked
Active
Viewed 485 times
2 Answers
17
The unary plus operator has higher precedence than the addition operator, just split your expression into multiple grouped expressions and it will seem pretty obvious:
var m = 6 + ( +( +( +( +( +( +( +( 6 ))))))));
//6 + 6

Christian C. Salvadó
- 807,428
- 183
- 922
- 838
3
The extra pluses are being treated as positive indicators. As in +1
.
-
What was the rational on adding positive indicators?? Anyone have any insight to this? – Dested Mar 27 '10 at 07:41
-
3so it's 6 + really really very positive 6? – Mike Two Mar 27 '10 at 07:44
-
@Dested: Rationale? Rationale? The inmates run that asylum, my friend. If anything, it would be symmetry. – Mar 27 '10 at 07:46
-
2@Mike Two: Yes. As positive as you can get without adding another plus sign. – Mar 27 '10 at 07:46
-
can you do the same thing with minus ( 6 - - - - - - 6) ? – Thilo Mar 27 '10 at 07:47
-
@Thilo: Apparently... but with a less stable effect, obviously. – Mar 27 '10 at 07:55
-
1@Dested: Some ideas on rationale here: http://stackoverflow.com/questions/727516/what-does-the-unary-plus-operator-do – AakashM Mar 27 '10 at 08:51