Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
117
rated 0 times [  123] [ 6]  / answers: 1 / hits: 32544  / 14 Years ago, tue, april 27, 2010, 12:00:00

Many times I've seen a semicolon used after a function declaration, or after the anonymous return function of a Module Pattern script. When is it appropriate to use a semicolon after curly braces?


More From » syntax

 Answers
152

You use a semicolon after a statement. This is a statement:





var foo = function() {
alert(bar);
};





because it is a variable assignment (i.e. creating and assigning an anonymous function to a variable).



The two things that spring to mind that aren't statements are function declarations:





function foo() {
alert(bar);
}





and blocks:





{
alert(foo);
}





Note: that same block construct without semi-colon also applies to for, do and while loops.


[#96957] Saturday, April 24, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jennie

Total Points: 593
Total Questions: 102
Total Answers: 106

Location: Federated States of Micronesia
Member since Fri, Sep 16, 2022
2 Years ago
jennie questions
;