The code OP provided can be included as a whole inside the body tag, or. really anywhere in the html document. as you can see, the function connect is declared on line 2, and then called on line 15. which means it will start running as soon as the page is loaded.
when the events fire, the callback function gets called. the callback function gets passed in as a parameter on line 15, it logs the event/res
Callback functions are a little bit tricky to understand at first, but basically it let's you pass a function into another function as a parameter. The function you pass in gets then called from inside the function called.
function doCallBack(cb){ cb() } doCallBack(()=>{ console.log("i got called from within doCallBack") })
reply
deleted by author
reply