javascript - JavaScript 中否定后的空格

标签 javascript styles negation

这是一个 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/

相关文章:

javascript - 我的 JS 字谜图解决方案的时间、空间复杂度

javascript - 在流体容器中垂直居中图像

wpf - 将 XAML Column 和 ListViewItem 中的文本居中

c# - 使用 javascript 的 Asp.net 内容占位符

c++ - 是否将 “flags”常量视为好样式? (C++)

wpf - 用于非路由事件的 EventSetter?

CSS:对 * 所有元素使用否定

python - Python 中 isinstance() 的否定形式

regex - 使用正则表达式进行字符串求反

javascript - 如果数组值包含某些字符串,如何过滤它