I just answered a question where I advised removing parentheses around a statement and was asked why, to which I had no answer when I realised that it caused no errors/warnings. I could only cite bad practice. But maybe I’m the one missing something…
I did my own tests:
(print('!')); // Outputs '!'
((print('!!'))); // Outputs '!!'
(1); // No output
(qwerty); // No output
(1==2); // No output
(1=2); // Syntax error
// etc...
Can someone shed some light on whats going on and of what use are ‘standalone parentheses’?
For all intents and purposes, no use at all.
As for what’s going on, they’re just delimiting expressions; there’s nothing special or complex about them. The reason why your
(1=2)does not work is the same reason why the same without parentheses would not work: you can’t assign a value (2) to a number (1).