Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHabibur Rahman Dipto
8,496 Pointsdeclaring function in variable
In javascript basic course dave mcfarland said that if we declare function in variable we need to put ' ; ' after the function block statement like this. if we don't it caused error.
var foo = function() {
};
But Andrew not using any semicolon in his course after declaring the the function in variable and caused no error.
var foo = function() {
}
3 Answers
eck
43,038 PointsIt is a best practice to include semicolons, but it is not required for your code to run correctly. You can read a bit about it here
JS will automatically add semicolons if you leave them out. There can be problems though; the semicolons are not always added in the spot you had intended. This can result in bugs or other undesired behavior. So it is best to be explicit and place those semicolons yourself :)
Sean T. Unwin
28,690 PointsSemantically a semi-colon should be used after a variable declaration, although most JavaScript interpreters will not fail if one is not used.
Habibur Rahman Dipto
8,496 Pointsthnx now i got the answer :)