2. How do you pass a function as a Parameter?
This function doesn't take in any parameters and when evaluated returns the string "hello".
Let's test it out by evaluating the function:
We see that we get a result of the string "hello":
This function, saySomething, evaluates whatever the parameter is passed into it.
You can see that the named function is defined as taking in a parameter named wordFunction.
Then it is evaluating it in the return statement.
The function adds and open and close parenthesis to the wordFunction parameter we passed in.
Now that we've done that, let's pass in our first function, sayHello, into the second function, saySomething, as a parameter.
When we evaluate it, we can see that it results in a string "hello":
Great - we were able to pass a function into another function as a parameter and have the second function evaluate the first function inside of it.
Since we've already looked at a Named Function function example above, we'll look at the other three ways:
Let's look at an examples of each kind:
Function assigned to a variable: