JavaScript syntax is the set of rules that tells the browser how to read and understand your code. Just like grammar is important in a language, syntax is important in programming.
If the syntax is wrong, the program will not run correctly. That is why learning JavaScript syntax rules is the first step toward writing clean and error-free programs.
In this lesson, you will learn the basic rules that every JavaScript developer must follow while writing code.
Basic JavaScript Syntax Rules
- JavaScript statements are written line by line
- Code is executed from top to bottom
- JavaScript is case-sensitive
- Instructions end with semicolons
- Code blocks are written inside curly brackets { }
Following these simple rules helps you avoid common mistakes.
This example follows all basic syntax rules. The variable name is written correctly, the value is inside quotes, and the statement ends properly.
The console.log() function prints the message in the browser console, showing that the code is valid and working.
JavaScript treats uppercase and lowercase letters as different. The variable userName is not the same as username.
This rule is very important to remember because many beginners face errors due to wrong letter cases.
This example shows how JavaScript uses curly brackets to group code into blocks. Blocks are used in conditions, loops, and functions.
By understanding and following JavaScript syntax rules, you build a strong foundation for learning more advanced topics like variables, loops, and functions.