Semicolon after Function

后端 未结 6 1473
广开言路
广开言路 2021-02-18 12:57

Is there a specific reason why some people put a semicolon after the curly closing function bracket?

void foo() {

};
6条回答
  •  -上瘾入骨i
    2021-02-18 13:23

    Just wanted to add my few opinions about semicolon insertion in general:

    1. As a matter of semantics .. semicolons after a function is okay if it is part of an executable statement like variable declaration for an anonymous function.

      var x = function(){ console.out(' Hello '); }

    2. Please be aware that if you add a semicolon after a function if un-necessary it will be counted as a statement in your LOC. Tools like Lint, Sonar etc will consider it as a Line of Code..Basically your client will be paying for the number of Lines of code.(like kloc metric ..Thousand lines of code was a common metric for billing your customers.)

    3. Also with semicolons, Javascript parser has a habit of inserting semicolons wherever it feels the current line's code might get broken like after a return statement in a function etc.The process of JS engine is called "Automatic Semicolon Insertion".You can google for Automatic semicolon insertion in ECMAScript standard.

提交回复
热议问题