From the course: JavaScript: Best Practices for Code Formatting
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
End statements with a semicolon - JavaScript Tutorial
From the course: JavaScript: Best Practices for Code Formatting
End statements with a semicolon
- [Instructor] You're probably used to seeing most lines in JavaScript code ended with semicolons. Although not strictly necessary, it's a best practice to include a semicolon at the end of every expression, such as a variable declaration, or a return statement. Some developers write JavaScript without semicolons. In a lot of cases, it's obvious to the parser where one statement ends, and the next begins, but there are some corner cases that can trip up even experienced developers. As a result, including semicolons is a simple way to make it clear where you intend your statements to end, and to illustrate the structure of your code for other developers who might need to work with it as well. JavaScript statements that end with a code block, such as an if/else block, don't need semicolons at the end, because the closing curly brace terminates the statement. But as a rule, you should terminate any statement that doesn't end with a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.