-
An expression is any piece of code that evaluates to (produces) a value. It can be as simple as a single primitive value, or a more complex interaction of values, operators and sub-expressions; a function can also be an expression when it is assigned to a variable name.
-
A binding (or variable) is any value or expression which has been assigned to a name (effectively labelled) in order for it to be stored in the computer’s memory, and then accessed and reused by the program whenever required. A variable is defined using the keyword
let
,const
, orvar
, followed by its chosen name (identifier). Unless it is an empty variable, the value is assigned (tied/bound) to the variable’s name using=
(the assignment operator) e.g.
let myVariable = a && b / 100;
The stored expression (or value) can be accessed with the variable’s name, which now
effectively represents it. However, the assignment of an expression (or value) to a name
does not have to be permanent, and can be reassigned (replaced with another) at any
time — except with variables defined with const
.
-
An environment is made up of all the bindings which are available for a program to access. As well as bindings defined within the program itself, an environment also includes a large pre-defined set of bindings, which either come already built-in to the JavaScript language, or are available in a particular environment (for example in a browser). This pre-defined set of bindings includes many standard functions which do not need to be programmed from scratch before they can be invoked (with their function names) to perform specific tasks or computations.
-
A function is a reusable “mini-program” placed within a value. The code of this mini-program will have been written to perform a specific task or computation, and will execute each time the function is called (invoked) with its name (the one it has been assigned to) appended with parentheses. The parentheses contain any required arguments — values fed into the function as parameters, and needed for the function to execute successfully.
-
An example of a function:
prompt("Enter your user number");
prompt
function name (binding name)
prompt();
function call
"Enter...number"
argument
-
A side effect is some kind of meaningful action produced by a piece of code (such as a function), and which occurs externally (outside of the program).
-
An example of a function that produces a side effect:
console.log("Hello, world!");
// "Hello, world!" printed to the browser's console.
An example of a function that produces a value:
Number("9");
// returns 9 as a number type (converts a string to a number type)
Number("string"); // returns NaN
-
Control flow is writing code that enables the computer to correctly decide which path to take through a program. In other words, having executed one statement, the program’s control flow will tell the computer which statement to execute next. For example, a program’s control flow could result in (i) one of two or more alternative branches being taken (conditional execution), which therefore leads to some statements being omitted, or (ii) a specific code block being repeated many times over (iteration).
-
Conditional execution is where the program’s control flow presents a Boolean expression and, depending on whether this expression evaluates to the Boolean value
true
orfalse
(i.e. whether the condition is met or not), only one of two alternative branches of code will be executed next. Where a series of consecutive Boolean expressions are used, only one of several alternative branches will end up being executed. -
Keywords used to invoke conditional execution:
if /* precedes the 1st (or only) condition (the Boolean
expression in parentheses) */
else if /* precedes any further Boolean expressions (in a series
of consecutive conditions) */
else /* precedes the statement or code block to execute if the
Boolean expression (or final Boolean expression in a
series) evaluates to false */