JavaScript Expressions

An expression is a single unit of JavaScript code that the JavaScript engine can evaluate, and return a value.

Expressions can vary in complexity.

We start from the very simple ones, called primary expressions:


4
0.06
("Hello, World")
false
true
this//the current scope
undefined
i//where i is a variable or a constant

Arithmetic expressions are expressions that take a variable and an operator (more on operators soon), and result into a number:


1 / 2
i++
i -= 2
i * 2

String expressions are expressions that result into a string:

Meaning if you concatinate two string it will give you single string as result which is ovious. We will talk more on concatination later.


"This is " + " a boy"

Logical expressions make use of logical operators and resolve to a boolean value:


a && b
a || b
!a