JavaScript Syntax

JavaScript syntax is the set of rules, how JavaScript programs are constructed:

The JavaScript syntax defines two types of values: Fixed values; Variable values. Fixed values are called Literals. Variable values are called Variables.

// How to create variables:
var x;
let y;

// How to use variables:
x = 5;
y = 6;
let z = x + y;


JavaScript Values

The JavaScript syntax defines two types of values:

Fixed values

Variable values

Fixed values are called Literals.

Variable values are called Variables.


JavaScript Literals

The two most important syntax rules for fixed values are:

1. Numbers are written with or without decimals:

EXAMPLE ❯


2. Strings are text, written within double or single quotes:

EXAMPLE ❯


JavaScript Variables

In a programming language, variables are used to store data values.

JavaScript uses the keywords varlet and const to declare variables.

An equal sign is used to assign values to variables.

In this example, x is defined as a variable. Then, x is assigned (given) the value 6:

EXAMPLE ❯


JavaScript Operators

JavaScript uses arithmetic operators ( + - * / ) to compute values:

EXAMPLE ❯


JavaScript uses an assignment operator ( = ) to assign values to variables:

EXAMPLE ❯


JavaScript Expressions

An expression is a combination of values, variables, and operators, which computes to a value.

The computation is called an evaluation.

For example, 5 * 10 evaluates to 50:

EXAMPLE ❯


JavaScript Keywords

JavaScript keywords are used to identify actions to be performed.

The let keyword tells the browser to create variables:

EXAMPLE ❯