

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Learn JavaScript
incomplete
2: Basic Variables
incomplete
3: let and const
incomplete
4: Why JavaScript?
incomplete
5: Comments
incomplete
6: Numbers in JS
incomplete
7: Numbers Review
incomplete
8: Increment and Decrement
incomplete
9: Undefined vs. Undeclared
incomplete
10: Null vs. Undefined
incomplete
11: Dynamic and Weak
incomplete
12: Same Line Declarations
incomplete
13: JavaScript's Speed
incomplete
14: Strings
incomplete
15: Template Literals
incomplete
16: Java vs. JavaScript
incomplete
17: Semi-Colons in JS
incomplete
18: String Encoding
incomplete
19: Camel Case in JS
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
In languages like C, C++, and Java, a semicolon is used as a statement terminator. For example, in C:
int x = 5;
This allows the compiler to know when a statement ends without relying on whitespace or newlines. For example, this is also valid C:
int x = 5; int y = 10;
In JavaScript, semicolons are optional as a terminating character. They can be inserted by the JavaScript engine automatically during the parsing phase. However, most developers (us included) prefer to use semi-colons to avoid any confusion or errors that can arise from automatic insertion.
// This works
let x = 5
let y = 10
// But we prefer this
let x = 5;
let y = 10;
Just so we can understand what semicolons allow for, let's fix a bug in the provided 2-statement program on a single line.
Run the code and notice that there is an error given. Fix the error on a single line by adding a semicolon as a separating character.