Loading lessons...
JavaScript Syntax
JavaScript Syntax
JavaScript syntax is the set of rules for how to write JavaScript code.
Statements
Programs are made of statements, which are instructions the computer runs one by one:
let x = 5;
let y = 6;
let z = x + y;
Semicolons
Statements often end with a semicolon ;. Semicolons separate statements and make code predictable. Most programmers always use them.
Values
JavaScript has two kinds of values:
- Literals: fixed values like
5or"Hello" - Variables: values stored in names, created with
letorconst
Identifiers
Names for variables, functions, and labels are called identifiers:
- Can contain letters, digits,
_, and$ - Must start with a letter,
_, or$ - Are case sensitive:
xandXare different - Cannot use reserved words like
letorfunction
Case sensitivity
let Name = "Ada";
let name = "Bob";
Name and name are two completely different variables.
Comments
Comments are ignored by JavaScript:
// This is a single line comment
/* This is a
multi-line comment */
TL;DR
- Code is made of statements, usually ending with
;. - Use
letandconstto create variables. - Identifiers start with a letter, underscore, or
$. - JavaScript is case sensitive.
- Use
//and/ /for comments.