When I use alert()
or console.log()
it works properly.
function greeting(name) {
alert('Hello ' + name);
console.log(`Hello ${name}`)
}
function processUserInput(callback) {
var name = prompt('Please enter your name.');
callback(name);
}
processUserInput(greeting);
But when I use return
it returns undefined
function greeting(name) {
let returnthis = `hello ${name}`
return returnthis
}
function processUserInput(callback) {
var name = prompt('Please enter your name.');
callback(name);
}
console.log(processUserInput(greeting));
Why is this happening?
How to return value?
I read this answer but can't understand.