Answer the question
In order to leave comments, you need to log in
Higher order functions?
var createScream = function(logger) {
return function(message) {
logger(message.toUpperCase() + "!!!")
}
}
const scream = createScream(message => console.log(message))
scream('functions can be returned from other functions')
var createScream = function(logger) {
return function(message) {
logger(message.toUpperCase() + "!!!")
}
}
const scream = createScream(console.log)
scream('functions can be returned from other functions')
const scream = createScream(message => console.log(message))
const scream = createScream(console.log)
Answer the question
In order to leave comments, you need to log in
There is no need, since you, in the first case, call the wrapper first and pass an argument to it. The wrapper passes the argument to console.log.
In the second case, you are passing the argument directly to console.log.
The difference is one extra function call. This is also a demo that shows passing a previously declared function and an anonymous function that is already doing something.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question