A valid unit of code required to resolve a value is known as an expression. It is a set of literals, operators, variables, and expressions required to evaluate a value. This value can be a string or any logical value. An expression results in a value that can be written wherever a value is expected. There are two types of expressions:
An expression that assigns a value to a variable
An expression that has a value
Consider the following example:
var A = 2;
In the preceding example, a value is assigned to variable A
, and for assigning that value to the variable, we use an assignment operator. Now consider another example:
2+3;
In this example, no value is assigned to a variable; however, it evaluates the result of 2+3
as 5
. The operator used in this expression is known as an addition operator.
Expressions in JavaScript can be broadly classified into three types: