-->

Should I put a Semicolon (;) when I use onclick=“”

2019-01-22 18:01发布

问题:

Should I put a Semicolon (;) when I use onclick=""

<p onclick="closeLightBox();">Click<p>

or

<p onclick="closeLightBox()">Click<p>

回答1:

The semi-colon in this position, is valid, but not mandatory.



回答2:

It is good practice to include it, since if you decide to add other statements after the call, it is clear and easy to do so. However, the code will run either way.



回答3:

I prefer a semicolon. I know it is optional (as it is many times in JS), but I like to be uniform and it helps to alert the person that the statement is complete.



回答4:

As an optional semicolon, it's a matter of taste.