What is an expression?
Basically, it is any valid unit of code that resolves to a value.
Below is a list of some JavaScript terminology that has the word "expression" to them.
Literal value expression: any part of a statement or another expression that is to be used exactly as it is, like number 2 in the statement a = b + 2.
Variable expression: is any symbol in a statement or another expression that represents a certain current value. An example is the variable b in the statement a = b + 2.
Arithmetic expression: is a correct combination of numbers, operators, variables, and parenthesis. It resolves then to a certain value. Example is b + 2 in the statement a = b + 2.
String expression: is basically same as an arithmetic expression but evaluates to a string type and uses a string operator. Example:
var mystring = 'alpha';
mystring += 'beta';
Logical expression: expression that evaluates to true or false. Example:
false || (3 == 4)
Assignment expression: is the assignment of a literal, variable, or arithmetic expression to a certain variable. Example is a = b + 2.
Primary expressions: are basic keywords and general expressions in JavaScript. Examples are this, new, super, Spread operator...
Anonymous function expression: is the assignment of a function not having a name to another variable. Anonymous function expressions are very similar and have almost the same syntax as function statements. Example:
let foo = function() { ... };
Named function expression: is the assignment of a function having a name to another variable. Example:
let foo = function add(a, b) { return a + b };
Immediately invoked function expression (IIFE): is a type of function expression that is called immediately, and the variables called inside the function won't affect the surrounding code outside the IIFE. IFFE's can be either anonymous or named. Example:
function myIIFE(){
...
})();
Note: the last parenthesis is needed to invoke the function expression, whereas the first set of parenthesis prevents the function from being treated as a normal function declaration.
Regular expressions: are patterns used to match character combinations in strings. They are also objects.
Top comments (0)