From the course: JavaScript: Best Practices for Code Formatting

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Don't rely on auto semicolon insertion

Don't rely on auto semicolon insertion - JavaScript Tutorial

From the course: JavaScript: Best Practices for Code Formatting

Start my 1-month free trial

Don't rely on auto semicolon insertion

- [Speaker] From a technical standpoint JavaScript doesn't absolutely require semicolons. Indeed, some developers write JavaScript without semicolons, relying on automatic semicolon insertion which is exactly what it sounds like. JavaScript's built in process for identifying a logical end of a statement and the beginning of a new one based on context. However, it's best not to rely on this mechanism, because it can have some unintended consequences. The classic example of where automatic semicolon insertion can behave differently than you want is when you use the return statement. If a return statement is followed by a line break parsers will treat it as as if it's followed by a semicolon. This means any continuation on the following line, such as a value to be returned will instead be treated as a separate statement. In the app.js file for this video lines 10-11 are meant to be a single statement. It's already clear from the…

Contents