Should I put a Semicolon (;) when I use onclick=""
<p onclick="closeLightBox();">Click<p>
or
<p onclick="closeLightBox()">Click<p>
Should I put a Semicolon (;) when I use onclick=""
<p onclick="closeLightBox();">Click<p>
or
<p onclick="closeLightBox()">Click<p>
The semi-colon in this position, is valid, but not mandatory.
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.
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.
As an optional semicolon, it's a matter of taste.