0

I sometimes like to work quickly, so I set a macro in my editor to always add a semicolon after an end curly-brace, even when not necessarily needed. For example:

var test=function(){
    //I realize the semicolon after the curly-brace below is required
};

function test(){
    //But is it safe to have on where it isn't required, like below?
};

As in, will it create errors, slow down the site, or create compatibility issues? I will remove these additional semicolons when I am finished developing the product, but for now, is it OK?

double-beep
  • 5,031
  • 17
  • 33
  • 41
CrazyMatt
  • 501
  • 1
  • 4
  • 12

2 Answers2

1

Note that there are cases where adding a semicolon after an ending curly bracket can cause issues, e.g.:

let data = {
  item1: [],
  item2: {}; // This semicolon is a syntax error
};
Gershom Maes
  • 7,358
  • 2
  • 35
  • 55
0

On a program level, it makes no difference to have this:

function() {

};

Or this:

function() {

}

I do recommend that you pick one way to do it and stick with it for the purpose of consistency.

You should also read through this post: Do you recommend using semicolons after every statement in JavaScript? A lot of good points on this subject are made there.

Community
  • 1
  • 1