1 min to read
What is syntax?
Syntax to programming is what grammar is to languages.
This article is written in English. In order to be grammatically correct, there is a set of structural rules I have to follow.
- I, shouldn’t, put, a, comma, after, every, word, and, declare, my, sentence, grammatically, correct.
- .I shouldn’t start my paragraph with a full stop.
- Its a grammatical error to omit the apostrophe in “it’s” when the meaning is “it is”.
The three above bullets are all poorly written, grammatically.
Syntax is exactly this, for programming languages. Each programming language has a defined syntax, which advises its users (developers) how to write code in the language.
The difference is if you make a grammatical error, the reader may not fully understand your message, but they could probably make an educated guess and move on.
If you make a syntactical error, your computer will not understand what you’re trying to do and will crash. Computers purposefully don’t try to guess what the user means and will crash to avoid unforeseen side effects.
If you’ve followed these articles, you should already know what a variable is. Each language specifies the Syntax of how to write a variable.
var x = "Hello World"
x := "Hello World"
x = "Hello World"
All three code snippets do exactly the same thing - they define a variable (
x) and set the value to the string