The term declaration means to declare the creation of variables and functions.
var color;
The code above is a declaration of a JavaScript var
variable
named color
.
Note: Declaration is not concerned with the storage (initialization) of values. Instead, its job is to declare the creation of variables and functions.
function multiplyNumbers() {}
The statement above declares that we create a JavaScript function named multiplyNumbers
.
The term initialization means to assign an initial value to a variable.
const color = "green";
In the snippet above, we initialized the color
variable with an initial value of “green”
.
let multiplyNumbers = function () {};
In the snippet above, we initialize the multiplyNumbers
variable with an initial value of a function.
Note: When the computer reads an initialized variable, it first evaluates the expression on the right of the assignment operator. Then, it assigns the resolved value to the variable on the left side.
For instance, the computer first evaluates 70 + 90
in the snippet below. Then, after the evaluation, it assigns the resolved value (160
) to the finalAnswer
variable.
const finalAnswer = 70 + 90;console.log(finalAnswer);
The term invocation means to invoke a piece of code.
var color = "green";// Invoke the color variable:console.log(color);// The invocation above will return:"green"
function multiplyNumbers(a, b) {console.log(a * b);}// Invoke the multiplyNumbers function:multiplyNumbers(3, 100);// The invocation above will return:300
Free Resources