Why so many semicolons in JavaScript?

前端 未结 10 1771
夕颜
夕颜 2021-02-13 03:22

I tend to be a prolific user of semicolons in my JavaScript:

var x = 1;
var y = 2;
if (x==y){do something};

I recently noticed that I was looki

10条回答
  •  一向
    一向 (楼主)
    2021-02-13 03:47

    Apart from code readability, the use of semi-colons comes into picture when you actually try to minify your code. After minification, if there are no semicolons in your code, javascript engine might fail to know which statement ends where as there will be no longer be any new lines in the code.

提交回复
热议问题