Variables: Declaration, Definition and Type

Robert Jeansoulin · 2018

Variables are made to receive values directly or through evaluated expressions compounding values and operators or results of function calls: the value is stored internally and the variable references this storage, and takes its value and its type. To fetch the value of a variable, it must have been identified in the lexical phase: which means to be “declared”. Often, JavaScript code starts with declaration instructions. This chapter looks back at the two steps in the interpretation of JavaScript (simplified): lexical-time and run-time. It details this double mechanism: declaration of the variables, initialization to undefined at lexical-time and definition of the variables at run-time. For a better understanding of the declaration mechanism in JavaScript, we must first learn what the “scope” of a variable is: the function declarations determine the overall logics of the notion of scope.

Read the paper · More papers on PaperTik