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

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

Posted by: admin November 30, 2017 Leave a comment

Questions:

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

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

or

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

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

Questions:
Answers:

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.

Questions:
Answers:

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.

Questions:
Answers:

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

Leave a Reply

Your email address will not be published. Required fields are marked *