📝 What You’ll Learn

  • What JavaScript syntax is
  • The basic rules of writing JavaScript
  • Common elements like variables, values, operators, and keywords
  • Syntax structure examples

📚 What Is Syntax?

Syntax refers to the set of rules that define how JavaScript code is written and structured. Just like grammar in a language, syntax ensures your code is valid and understandable by the browser.

🔤 JavaScript Is Case-Sensitive

JavaScript treats uppercase and lowercase letters differently.

let name = "Alex";
let Name = "Taylor";

console.log(name); // Alex
console.log(Name); // Taylor

These are two different variables!

🧱 JavaScript Structure

A basic JavaScript program is made up of:

  • Statements – actions or instructions (let x = 5;)
  • Blocks – code grouped inside {}
  • Semicolons – used to end statements (optional but recommended)

🏷 Identifiers and Keywords

  • Identifiers are names you assign (e.g., userName, total)
  • Keywords are reserved words in JavaScript (e.g., let, const, if, function)
let total = 100;

🔢 Values and Variables

JavaScript uses variables to store values.

let message = "Hello!";
let age = 25;

Values can be numbers, text (strings), booleans, arrays, etc.

➕ Operators

JavaScript supports various operators to perform operations:

  • Arithmetic: +, -, *, /
  • Assignment: =, +=, -=
  • Comparison: ==, ===, !=, >
  • Logical: &&, ||, !

Example:

let result = 10 + 5;

📄 Comments

You can add notes in your code using comments:

// This is a single-line comment

/*
  This is a multi-line comment
*/

Comments are ignored by the browser and help others understand your code.

📘 Recap

  • JavaScript syntax defines how code is written
  • Case sensitivity and semicolons matter
  • Use variables, operators, and keywords correctly
  • Always comment your code for clarity