liveBook · Manning

Identifier registration

As explained in Secrets of the JavaScript Ninja, Second Edition

The pre-execution process of recording declared identifiers and their initial bindings in a lexical environment.

A function can run before its declaration appears in the code. JavaScript makes this possible by registering identifiers when it creates a lexical environment, before executing that environment’s code. section 5.5.3

In global and function environments, registration scans for function declarations without entering other functions’ bodies. It creates a function for each declaration and binds it by name; a later declaration can overwrite an existing binding. Function expressions and arrow functions are not registered this way. Function environments also receive the implicit arguments identifier and formal parameters with their argument values. section 5.5.3

const firstRonin = "Kiyokawa";
check(firstRonin);
function check(ronin) {
  assert(ronin === "Kiyokawa", "The ronin was checked! ");
}

See a function called before its declaration; its parameter receives the value passed at the call site. section 5.5.3

How Secrets of the JavaScript Ninja, Second Edition covers it

How deep it goes
Details two execution phases, function parameters, and function-declaration bindings, while leaving variable-kind and block-environment rules unspecified.
Examples
Contrasts calling a function before its declaration with function expressions and arrow functions that are not registered as declarations.
What you can do after
Evaluate/understand why a function declaration can be called before its textual definition.
How it connects
Connects lexical environments with function declarations, function parameters, function expressions, and arrow functions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Second Edition. The section links point to the parts of the book it draws on.