This is a javascript coding style question. Is there any reason for putting a space after the negation operator? I've seen that in the source code of angularjs and I can't figure out if there is any benefit to this. Example: writing !myVar
vs ! myVar1
Asked
Active
Viewed 720 times
0

Keyamoon
- 1,785
- 17
- 16
-
2I don't like it, but it's a matter of style, there's no difference in meaning. – bfavaretto Mar 31 '13 at 15:11
-
This is not a standard convention. Can you give an example where you've seen somebody do this? – Dave Mar 31 '13 at 15:14
1 Answers
2
There is no difference. From the spec:
Simple white space and single-line comments are discarded and do not appear in the stream of input elements for the syntactic grammar.
You can use either form, but I've very rarely seen spaces used between unary operators and operands in that way.
Consider the spacing often seen between other operators. This situation is no different:
var x = 1 + 2;
var y = 1+2; // These are identical

James Allardice
- 164,175
- 21
- 332
- 312