Is it good practice to start all JS files with a semi colon to account for any bad scripts included before it? Or don’t bother?
Thanks
;(function(){ /* my script here */ })();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Do bother, more and more people leverage the power of ASI and write semicolonless JavaScript. In semicolonless JS world that’s the “rule”, you put a semicolon before raw expressions, like
;(), or;[]or;//, as well as after'use strict';and omit them everywhere else. Raw expressions are not very common, except the typical IIFE.Even if you write JS with semicolons, that particular one is safe and will do more good than bad.