1- # JavaScript Advanced Functions: Basic Functions Review
1+ # Functions: Continued
22
33## Learning Goals
44
@@ -381,10 +381,8 @@ Recall the IIFE discussion. Since what's inside an IIFE can't be seen, if we
381381wanted to let just tiny bits of information leak back out, we might want to
382382pass that information back out, through a closure.
383383
384- _ Note: We're also using destructuring assignment, don't forget your ES6 tools!_
385-
386384``` js
387- const [ answer , theBase ] = (
385+ const array = (
388386 function (thingToAdd ) {
389387 const base = 3 ;
390388 return [
@@ -398,31 +396,31 @@ const [answer, theBase] = (
398396Note that the value on the right of the ` = ` in the first line is a function
399397expression. That function takes a single argument and returns an array that
400398contains two functions. The ` (2) ` after the function expression executes that
401- function (instantly), and the two inner functions are stored in the variables
402- ` answer ` and ` theBase ` by the destructuring assignment .
399+ function (instantly), and the two inner functions are stored in the ` array `
400+ variable .
403401
404402Go ahead and copy the code above into your browser console and take a look at the
405- values of ` answer ` and ` theBase ` . You should see the following:
403+ values of the two elements of ` array ` . You should see the following:
406404
407405 ``` js
408- answer ; // => ƒ () { return base + thingToAdd; }
409- theBase ; // => ƒ () { return base; }
406+ array[ 0 ] ; // => ƒ () { return base + thingToAdd; }
407+ array[ 1 ] ; // => ƒ () { return base; }
410408 ```
411409
412410However, if you try looking at the value of ` base ` in the console you'll get a
413411reference error: the value of ` base ` is not accessible outside the function it's
414- defined in. Now go ahead and _ call_ ` answer ` and ` theBase ` ; you should see the
415- following:
412+ defined in. Now go ahead and _ call_ the two returned functions ; you should see
413+ the following:
416414
417415``` js
418- answer (); // => 5
419- theBase (); // => 3
416+ array[ 0 ] (); // => 5
417+ array[ 1 ] (); // => 3
420418```
421419
422- The ` answer ` and ` theBase ` functions are ** closures** ; they have access to the
423- ` base ` variable because it's defined in their parent function. When they're
424- executed, they "let out" the values of the sum and the original base number,
425- allowing us to see them.
420+ The two functions being returned in ` array ` are ** closures** ; they have access
421+ to the ` base ` variable because it's defined in their parent function. When
422+ they're executed, they "let out" the values of the sum and the original base
423+ number, allowing us to see them.
426424
427425## Define ` Scope Chain `
428426
0 commit comments