Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semicolon after Function

Tags:

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

void foo() {  }; 
like image 836
user695652 Avatar asked Apr 03 '12 16:04

user695652


People also ask

Do you need semicolon after function in C++?

C++ semicolon is used to tell the compiler where a statement ends. The body of a function or any scope block isn't a statement in and of itself so it's pretty much only needed after } when defining an object.

What happens if we put semicolon after if statement?

Do not use a semicolon on the same line as an if , for , or while statement because it typically indicates programmer error and can result in unexpected behavior.

Should JavaScript functions end with semicolon?

JavaScript Learn JavaScript Quick Course BeginnersAdding semicolons after every function is optional. To avoid undesirable results, while using functions expressions, use a semicolon.

Do JavaScript functions need semicolons?

This is all possible because JavaScript does not strictly require semicolons. When there is a place where a semicolon is needed, it adds it behind the scenes. This is called Automatic Semicolon Insertion.


1 Answers

Not really, the semicolon there makes no difference. It's probably a matter of habit.

You can put as many semicolons if you want though in C++11:

void foo() {  };;;;;;;; 
like image 181
Luchian Grigore Avatar answered Dec 03 '22 08:12

Luchian Grigore