JavaScript #5 — Syntax

These JavaScript articles are written for people who are interested in coding and are meant to provide an introduction to the programming world.

In order to speak a language you need to know its grammar. The same applies for learning a programming language. This grammar, you need to learn, is called syntax in the programming world.

In computer science, the syntax of a computer language is the set of rules that defines the combinations of symbols that are considered to be correctly structured statements or expressions in that language. This applies both to programming languages, where the document represents source code, and to markup languages, where the document represents data.
— Wikipedia, read more about syntax

If you want to say something in English, you need to put the words into the correct sequence (order) for people to understand you. Let’s think about this example — you want to say that you are hungry. There is a difference if you say I am hungry versus am I hungry. If you wouldn’t know English grammar, you could even say hungry am I which is an invalid sentence for what you want to say and people wouldn’t understand that they are supposed to give you some food.

As we are talking to people using correct English grammar, we need to talk to the computer using correct programming grammar.

Mental exercise

Imagine that you would like to create a new and very simple programming language that can only define a number and then increase its numeric value. You would need to, somehow, tell the computer what to do.

Lets use English language to write that program. Here is an example of a programming language you could make.

Your new programming language would need to recognize some keywords to be able to translate create number named into low-level instructions that would command the computer to allocate a piece of memory, big enough to store a number, for the program. The piece of computer memory would be called myAge and the value stored in that piece of memory would be set to 25.

The real programming languages, like JavaScript, are trying to be more concise but yet still readable by humans. Here is how we would write the same code using JavaScript programing language.

Do not try to put this code into your code editor yet. You will have an opportunity to learn how to define and modify variables in the next article.

Final words

It might be a bit cryptic for the first time, but it will become more clear to you once you start learning the syntax of JavaScript language and experiment with the code. It is going to take some time, self-motivation and perseverance before you will be able to write your own programs.

Next Step

JavaScript #6 — Defining Variables — You are going to learn syntax of how to define your own variables.