Convert the function named functionDeclaration to an anonymous function expression and assign it to a variable called myFunc.
function functionDeclaration() {
let myFunc = str
return "Hi there!";
}
console.log(myFunc())
I'm new to coding. What am I doing wrong? It's supposed to print 'Hi there!' but keeps giving me a reference error message.
Thank you for your help!
Your function expression could be like,
const func = function functionDeclaration() {
return "Hi there!";
}
let myFunc = func()
console.log(myFunc);
I am not sure what is the purpose of let myFunc = str, but give this a try -
function functionDeclaration() {
// let myFunc = str
return "Hi there!";
}
const myFunc = () => {
return functionDeclaration.call(this);
}
console.log(myFunc());
Your answer:
let myFunc = function() {
return "Hi there!";
}
Please read Constructor vs. declaration vs. expression