JavaScript Syntax

JavaScript syntax is the set of rules that define a correctly structured JavaScript program.

Values: Literals and Variables

JavaScript has two types of values: fixed values (literals) and variable values (variables).

Literals
// Number literals
console.log(10.5);
console.log(1000);

// String literals
console.log("Hello World");
console.log('Single quotes work too');

Variables

Variables are used to store data values. JavaScript uses let, const, and var keywords to declare variables.

Variables
let x = 5;
let y = 6;
let z = x + y;
console.log("x + y =", z);

Operators and Expressions

Arithmetic and Assignment
let a = (5 + 6) * 10;   // arithmetic
console.log(a);          // 110

let name = "John";       // assignment
console.log(name);

Case Sensitivity

JavaScript is case-sensitive. Variables named lastName and lastname are different variables.

Case Sensitivity
let lastName = "Doe";
let lastname = "Smith";   // completely different variable!
console.log(lastName);    // Doe
console.log(lastname);    // Smith

Naming Conventions

JavaScript programmers use camelCase for variable names: firstName, masterCard, interestRate.

ConventionExampleUsed For
camelCasefirstNameVariables, functions (standard JS)
PascalCaseFirstNameClasses, constructors
UPPER_SNAKEMAX_SIZEConstants
underscorefirst_nameSometimes (older style)
📝 Note: Hyphens (like first-name) are not allowed in JavaScript identifiers — they are reserved for subtraction.
Exercise:
Which naming convention is standard for JavaScript variables?
Try it YourselfCtrl+Enter to run
Click Run to see the output here.