Reputation: 1520
Question: Why isn't the event listener being set?
//ADDING THE EVENT LISTENER
document.addEventListener('DOMContentLoaded', init);
//DELCARING INIT, PASSING BLANK PARAM, STATEMENT
var init = () => console.log('Is Firing');
Upvotes: 1
Views: 3796
Reputation: 79
init is a function expression , which means hoisting doesn't happen for it, so you should pull the function expression up before the listener binding. I suggest you study the function hoisting. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/function#Function_declaration_hoisting
Upvotes: 0
Reputation: 36703
Your init
should be declared first before using it.
//DELCARING INIT, PASSING BLANK PARAM, STATEMENT
var init = () => alert('Is Firing');
//ADDING THE EVENT LISTENER
document.addEventListener('DOMContentLoaded', init);
Upvotes: 4