Closure Exercise 1

by Matthew Day

JavaScript

const hello = function(param2) {  // 3
  return(param1) => {  // 4
    console.log(`${param2} ${param1}!`);  // 6
  }
}
const greeting = hello('Hello');  // 2, 5

greeting('Jason');  // 1

/*
1) We fire `greeting('Jason')`
2) Because `greeting('Jason')` is equal to the return value of `hello('Hello')`, `hello('Hello')` fires in order to return that value
3) `param2` is equal to 'Hello', the argument we passed in when `hello('Hello')` fired
4) The function that we return here is equal to `greeting('Jason')` (as we mentioned in no. 2 above)
5) `param1` is equal 'Jason'
6) We log both `param1` and `param2` to the console.
*/