Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript
programming
variable
definition
communitycreator

What is declaration vs. initialization vs. invocation?

Oluwatobi Sofela

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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.

RELATED TAGS

javascript
programming
variable
definition
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring