Chapter 04
JavaScript Syntax
JavaScript syntax is the set of rules used to write valid and understandable JavaScript code.
01 • Learn
What is JavaScript Syntax?
- Syntax defines how JavaScript code should be written.
- JavaScript uses keywords, variables, operators, values, expressions, and statements.
- JavaScript is case-sensitive, so name and Name are different identifiers.
- String values are normally written inside quotes.
02 • Syntax
Syntax
let name = 'AIFA'; let marks = 85; console.log(name); console.log(marks);
03 • Example
Example
Try understanding this code before running it.
let studentName = 'Priya';
let marks = 92;
if (marks >= 40) {
console.log(studentName + ' passed');
}
04 • Remember
Important Points
- Reserved keywords should not be used as variable names.
- String values should be written inside quotes.
- Good indentation improves code readability.
- Brackets, parentheses, quotes, and braces must be properly matched.
05 • Avoid
Common Mistakes
- Changing variable spelling in different places.
- Missing a quote or bracket.
- Using HTML syntax directly as if it were JavaScript syntax.
06 • Practical
Real-World Use
Correct syntax helps JavaScript applications execute as expected without syntax errors.
07 • Practice
Practice Exercise
Practice: JavaScript Syntax
Create studentName and marks variables. If marks are 40 or more, print 'Pass' in the console.
Ready to write code?
Open the JavaScript editor and run your code with live output.