Many people write `[removed]void(0)` instead of `[removed]void 0` in hrefs. Do the parentheses do anything?

后端 未结 3 870
执念已碎
执念已碎 2021-01-01 21:23

I see people write void(0) all the time, but I don\'t understand why people use parentheses. As far as I can tell, they have no purpose. void is no

3条回答
  •  温柔的废话
    2021-01-01 21:59

    This link explains it for you.

    One thing this clarifies is that void is an operator (not a function).Because of this void(0) is technically incorrect though in practice implementations allow it to be used this way it should be used without parentheses e.g. void 0.

    So its technically wrong to use void(0) but in practise void has two different syntaxes:

    void (expression)
    void expression
    

    MDN already tells you that, though no explicit statement has been made regarding the two syntaxes, as its not technically correct.

    Courtesy:

    • http://www.coderenaissance.com/2011/02/javascripts-void-operator-explained.html
    • http://www.w3resource.com/javascript/operators/void.php
    • https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/void

提交回复
热议问题