console.log(x);

var x = ‘Hello world’;

We would get an error and our code would not execute correctly. The reason for this error is simple, right? x isn’t defined at the point at which we ask the browser to log the variable x. So x returns ‘undefined’.

To recap, JavaScript statements are executed in the exact order that they are written, and variables must always be defined before use. Simple stuff, but critically important to understand.

Semi-colons

You might have noticed semi-colons at the end of each statement we have written so far and wondered what part they play in the statement. A semi-colon in JavaScript terminates a statement. It marks the end of the statement and instructs the next statement to run. Interestingly, semi-colons aren’t actually required at all as a method of executing a statement. It’s totally fine to leave a semi-colon off the end of a statement, and the statement will still execute the same; however, it is strongly recommended to make use of semi-colons as it helps to clearly define each statement, and also allows you to specify multiple statements on a single line, like so: