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 trial

JavaScript AngularJS Basics (1.x) Using Angular's Built In Directives Using ng-blur and ng-class to Improve User Experience

melissa yip
melissa yip
6,952 Points

ng-blur requires semicolon?

Why does the code inside ng-blur require a semicolon but code inside ng-click or other directives do not?

3 Answers

Seth Kroger
Seth Kroger
56,413 Points

The semi-colon isn't required in an Angular expression unless you're breaking up two or more separate statements.

melissa yip
melissa yip
6,952 Points

Ok. I ask because in the video Huston has a semicolon after his ng-blur statement, but my code still works after removing it. Thanks.

The statement inside the quotes is actually a line of JavaScript. Programmers are so used to putting a semicolon at the end of a statement, they'll sometimes even put it where it's really not needed.

Side note: JavaScript actually doesn't require a semicolon to end a line of code. The JavaScript interpreter will attempt to make an educated guess as to when you are ending your statement. In this case, the close quote does the job. In a regular program or code block, hitting enter at the end of a line is usually enough. The semicolons are there for clarity, tradition, and for a small number of cases where they are actually needed at the end of a line.