How come the below code is not printing in the console. If I use a normal function it works.
document.addEventListener('DOMContentLoaded', recipeController);
const recipeController = () => console.log("hello");
How come the below code is not printing in the console. If I use a normal function it works.
document.addEventListener('DOMContentLoaded', recipeController);
const recipeController = () => console.log("hello");
const
variables must be declared before they are used. They are not hoisted.
Functions are forward-referencing (hoisted), what you have here is a variable declaration (non-hoisted). In this case, you need to declare your recipeController
above your event listener.
const recipeController = () => console.log("hello");
document.addEventListener('DOMContentLoaded', recipeController);