Expressions Everywhere

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.

  1. 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.

  2. Variable expression: is any symbol in a statement or another expression that represents a certain current value. Example is the variable b in the statement a = b + 2.

  3. 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.

  4. String expression: is basically same as arithmetic expression but evaluates to a string type and uses a string operator. Example:
    var mystring = 'alpha';
    mystring += 'bet';

  5. Logical expression: expression that evaluates to true or false. Example:
    false || (3 == 4)

  6. Assignment expression: is the assignment of a literal, variable, or arithmetic expression to a certain variable. Example is a = b + 2.

  7. Primary expressions: are basic keywords and general expressions in JavaScript. Examples are: this, new, super, Spread operator...

  8. 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() { ... };

  9. 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 };

  10. 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 are needed to invoke the function expression, whereas the first set of parenthesis prevents the function from being treated as a normal function declaration.

  11. Regular expressions: are patterns used to match character combinations in strings. They are also objects.

Show Comments