JavaScript syntax refers to the set of rules that define how JavaScript programs are written and interpreted. It includes variables, operators, functions, statements, and expressions that control the behavior of a script.
✔ JavaScript is case-sensitive (var name
≠ var Name
).
✔ Statements end with a semicolon (optional but recommended) → console.log("Hello");
✔ Curly braces {}
group code blocks (e.g., functions, loops).
✔ Comments allow adding explanations (// single-line
or /* multi-line */
).
JavaScript code is executed as a series of statements. Each statement performs an action.
Example:
let x = 10; // Variable declaration
let y = 20; // Another variable
let sum = x + y; // Calculation
console.log(sum); // Output result
✔ Effect: Displays 30
in the console.
Variables store data values. JavaScript provides let
, var
, and const
to declare variables.
Example:
let name = "John"; // String
var age = 25; // Number
const PI = 3.14; // Constant
✔ let
is preferred over var
due to better scoping rules.
JavaScript has different data types:
String: "Hello"
Number: 42
Boolean: true / false
Array: ["Apple", "Banana"]
Object: {name: "John", age: 25}
Example:
let isStudent = true;
console.log(typeof isStudent); // Output: "boolean"
Operators perform operations on variables and values.
✔ Arithmetic Operators: +
, -
, *
, /
, %
, **
✔ Assignment Operators: =
, +=
, -=
, *=
, /=
✔ Comparison Operators: ==
, ===
, !=
, !==
, >
, <
, >=
, <=
✔ Logical Operators: &&
, ||
, !
Example: