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 - JavaScript Tutorial
From the course: JavaScript: Best Practices for Code Formatting
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…
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.
Contents
-
-
-
-
-
(Locked)
End statements with a semicolon5m 10s
-
(Locked)
Don't rely on auto semicolon insertion4m 19s
-
(Locked)
Standardize line length6m 33s
-
(Locked)
Use commas consistently3m 38s
-
(Locked)
Include a comma in a list of values3m 21s
-
(Locked)
Challenge: Optimize punctuation31s
-
(Locked)
Solution: Optimize punctuation5m 23s
-
(Locked)
-
-