Clarifying: Variable Declaration and Initialization

Sources:
tutorialspoint
korenlc
stackoverflow
stackoverflow2

 

variable declaration – use var keyword before the variable name to create the variable

Example 1: Declaring a variable

var day;

Example 2: Declaring multiple variables

var name, birthday, age, gender;

 

variable initialization – the variable is given a first value to grasp (going with the ‘variables are tentacles’ analogy)

NB: “define a variable” and “initialize a variable” is a “value assignment”

-Technically, all variables are initialized with the value undefined upon their declaration

CHECK: But this does not count as an assignment.

 

  • initialization can be done at the time of variable creation or later

Example 3: Initializing a variable at the time of variable creation

var name = "James Bond";

Example 4: Initializing a variable after declaration

var name; 
name = "Atalanta";

 

QUESTION: Is “define a variable” and “initialize a variable” interchangeable?