What is declaration vs. initialization vs. invocation?

Declaration

The term declaration means to declare the creation of variables and functions.

Example 1

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.

Example 2

function multiplyNumbers() {}

The statement above declares that we create a JavaScript function named multiplyNumbers.

Initialization

The term initialization means to assign an initial value to a variable.

Example 1

const color = "green";

In the snippet above, we initialized the color variable with an initial value of “green”.

Example 2

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);

Invocation

The term invocation means to invoke a piece of code.

Example 1

var color = "green";
// Invoke the color variable:
console.log(color);
// The invocation above will return:
"green"

Example 2

function multiplyNumbers(a, b) {
console.log(a * b);
}
// Invoke the multiplyNumbers function:
multiplyNumbers(3, 100);
// The invocation above will return:
300

In summary

  • Declaration declares the creation of variables and functions.
  • Initialization assigns initial values to variables.
  • Invocation executes a piece of code.

Free Resources

Attributions:
  1. undefined by undefined