Definition

The example in Listing 8.1 is a function definition. With a function definition, you are saying that you intend to use the code in the function body eventually, and perhaps multiple times, but not yet. When code is being executed, the runtime executes the first instruction in the file and then moves on to the second, then the third, and so forth. However, when the runtime encounters a function definition, it registers the function and then skips over the function body. To see what I mean, try out the code in Listing 8.2.

Listing 8.2 A Function

console.log('Instruction 1');console.log('Instruction 2');function instructionThree () {  console.log('Instruction 3');}console.log('Instruction 4');/* Output: ...

Get Learning to Program now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.