Programming Basics
What Is Syntax in Programming?
Syntax is the set of grammar rules that defines how code must be written in a language, from keywords and brackets to indentation.
Definition
Syntax is the grammar of a programming language: the rules for how words, symbols and spacing must be arranged for the code to be valid. Every language has its own syntax.
Python uses indentation to group code, while Java, C and JavaScript use curly braces and end statements with semicolons.
How it works
Before running code, the compiler or interpreter parses it against the syntax rules. If a rule is broken, it stops with a syntax error and points to the line where it got confused.
Syntax only covers form. Code can have valid syntax and still be wrong, which is called a logic error.