这是一个 JavaScript 编码风格问题。是否有理由在否定运算符后面添加空格?我在 angularjs 的源代码中看到了这一点,但我不知道这样做是否有任何好处。示例:写 !myVar
与 ! myVar1
最佳答案
没有什么区别。 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.
您可以使用任何一种形式,但我很少看到以这种方式在一元运算符和操作数之间使用空格。
考虑其他运算符之间常见的间距。这种情况没有什么不同:
var x = 1 + 2;
var y = 1+2; // These are identical
关于javascript - JavaScript 中否定后的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15730830/