JavaScript Syntax

JavaScript Values

JavaScript syntax defines two types of values:

JavaScript Literals

Numbers

Example
10.50
1001

Strings

Example
"Hello World"
'Hello World'

JavaScript Variables

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

Example
let x;
x = 5;

JavaScript Operators

JavaScript uses arithmetic operators to compute values:

Example
(5 + 6) * 10

JavaScript Expressions

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

Example
5 * 10
x * 10
"John" + " " + "Doe"

JavaScript Keywords

JavaScript keywords are reserved words that cannot be used as variable names:

JavaScript Identifiers

Identifiers are names used to identify variables, functions, and objects. Rules:

JavaScript Comments

Comments are used to explain code and are ignored by JavaScript:

Example
// This is a single-line comment

/*
This is a
multi-line comment
*/

JavaScript is Case Sensitive

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

Camel Case

JavaScript programmers tend to use camel case for variable names:

Example
let firstName = "John";
let lastName = "Doe";