During the introduction I briefly touched on variables, and how to output results. Let’s look into this a bit closer.

First, it’s important to understand Javascript syntax when writing code. Syntax is the format in which we write code, such that the Javascript engine can understand this code. Javascript parses the code in order to execute it, so unless the syntax of the code is in the correct format, Javascript won’t understand what it’s looking at.

Let’s look at the first line from the introduction example:

var x = 10;

So what exactly does the above mean? Programming languages, Javascript included, have a number of different constructs that need to be understood, which include some of the following:

  • reserved words
  • data types
  • functions
  • classes

Reserved words are words that the programming language reserves for it’s own use, so you can’t use these names as names for your variables, function or classes. Some examples of reserved words are var, let, const, if, then, else, while, function.

Notice that the first reserved word in the list is var? It also happens to be the first word in our code line above. The Javascript programming language is case sensitive, so var is a valid reserved word, but VAR all other combinations are NOT, and could technically be used as variables, functions or classes, although doing so is NOT recommended.

Here the var is a token, and tells Javascript that what follows will be a variable name, along with an optional assignment for the variable. In this case, we are creating a variable called x and assigning it the value 10. The semicolon on the end tells Javascript that this bit of code is done. Again, here the semicolon is optional but is good coding practice to denote that the assignment is complete. Javascript will also recognize it’s complete because it’s the end of the current line.

var y = 15;

The second line, again, is