An expression is the part of a statement or a line of code which returns a value
It can be a combination of one or more constants, variables, functions, and operators that the programming language interprets (or evaluates) to return a value
The resulting value of an expression is usually one of various primitive types, such as numerical, string, boolean or complex data type like lists
Consider following example javascript code
function ncx() {
var x;
x = "seventeen";
var y = 17 + 2;
x = y;
x = x + 17 + 2 * math.sqrt(17);
return x;
}
ncx();
In the statement x = "seventeen"
, the value "seventeen"
is the expression
In var y = 17 + 2
, 17 + 2
is the expression
In x = y
, y
is the expression
In x = x + 17 + 2 * math.sqrt(17);
, x + 17 + 2 * math.sqrt(17)
is the expression
Also in the same statement, x
, 17
, 2 * math.sqrt(17)
etc can be considered as separate expressions
In the statement ncx();
, ncx()
can be considered as an expression, although its return value is not used
Variables and functions used in an expression are evaluated to get their values, which can be primitive or complex
Numbers, strings, booleans etc are primitive data-types, which are defined by the programming language
Languages also define data-types called as complex datatypes, like a list
(of primitive data-types and/or complex data-types) and map
(or dict
)