When you create the program or application in JavaScript or in other program language, you might be
excited by how they work and give us the results.
But you need to know that our code is not a wizard before we create the programs.
There has been already created also a program by other smart people which can read our codes, translate
them and execute in order to make our codes understandable.
For that program, we need to follow the set of rules, which is called Syntex.
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 a correctly structured document in that language.
So the JavaScript syntax is the set of rules, how JavaScript programs are constructed.
We always need to be assured that the grammar of our code is valid.
That's the main work of syntax parser, which is the part of JavaScript engine.
It checks the code character by character and if something is wrong, then it throws an error regarding
syntax parser and JavaScript engine, we will discuss how they work in depth in comic sections.
Let's take a look on that example here we have the variable with name, first name and its value, John.
Maybe you don't know yet what variable is or you may not know from other programming languages, it
doesn't matter for now because I'm just trying to demonstrate how important it is to write syntactically
correct code.
So, as we said, the syntax pasturage the code character by character, when it finds the VR and space,
it understands that this is a variable declaration, that it expects the name of the variable and finds
it, which is first name in this case, that it meets the equals sign and finds out that the variable
has the value, which is, John, after the value, the syntax parser says the semicolon and understands
that this is the end of the statement.
So the code is valid and the syntax parser continues to read the next coming Cote's.
If it meets something like this, it will find that there is no equal sign between name of the variable
and the value.
Smith So syntax parser is expecting here the equals sign, but instead of it, it finds other character
which makes the code invalid and therefore syntax parser throws an error.
All right, let's write the same example in brackets.
Their first name equals the John.
Then last name.
Smith.
Reload the page and you see we have syntax error on the third line in script, I just file, it tells
us that we have unexpected string value.
If we place your equal sign that the code will work all right throughout the course, you will learn
how to write the appellate code that will help you to avoid getting errors and mistakes.
But anyway, errors and bugs are our friends because they are the best teachers to write the code correctly.
OK, in this lecture, we have talked about the syntax and how the syntax parser with the code line
by line and character by character.
See you in the next video.