I have the following IIFE (Immediately Invoked Function Expression):
(async () => {
const brwSettings = await brwApi.get(
ajax_var.resturl + "?_wpnonce=" + ajax_var.restnonce
);
settingsDataAvailable(brwSettings);
})();
Below this IIFE, I declare the settingsDataAvailable
function like this:
const settingsDataAvailable = (data) => {
console(data);
};
And this is working fine.
However, if I call settingsDataAvailable
outside of the IIFE, it gives me the error Uncaught ReferenceError: Cannot access 'settingsDataAvailable' before initialization
.
(async () => {
const brwSettings = await brwApi.get(
ajax_var.resturl + "?_wpnonce=" + ajax_var.restnonce
);
})();
settingsDataAvailable(brwSettings); // throws an error
const settingsDataAvailable = (data) => {
console(data);
};
Why does this throw an error but the code snippet earlier did not?