The JavaScript interpreter in the web browser condenses the white spaces the same way it does for html, and in order to interpret code, the compiler needs to understand it as a set of instructions. Similar to how we read steps of instructions from a page, it needs to understand where one step ends, and another begins, and sometimes the instruction is too long to fit on one line. So, the language needs a way to seperate the steps that allows each step to take up multiple lines.
Human language is broken up into sentences by using periods. JavaScript is broken up into what are called statements, using semicolons. The semicolons ensure that the interpreter knows where each statement ends. This also allows you to place 2 or more commands on the same line if you want to. Forgetting a semicolon can sometimes cause a frustrating error that can take time to troubleshoot, so make sure you're placing them correctly.
There are some situations where statements are grouped together using curly braces (also known as curly brackets,) and do not end with semi-colons, since the statements themselves already have semicolons. These are called block statements. Functions and conditionals are examples. Other times curly braces are used to group information within a statement, such as in objects. We'll cover those situations in future sections. Right now, it's only important to have a basic understanding of statements.
// single line declaration statement
var
string = 'this whole line is a single statement';
// single statement on multiple lines
console.log(
"This is
a statement
on multiple lines!"
);
// both are statements because they each end with a semicolon!
In the next section, we'll talk about keywords and variables.