1

I know is kind of a dumb question but I'm kinda confused, tried to look up on the internet but couldn't find anything so..

when in JS (ES6) I declare an arrow function as const, how can I invoke it when page is loaded?

es.

const bigBla = async () => { bla bla };

tried smt like onload="bigBla()" but doesn't work, also tried to invoke it at the end of the JS file but won't work in the HTML file (need to change innerHTML of a span element/src of an iframe, data come from http request), whereas if i declare function bigBla(){...} and use onload="bigBla()" i have no problems. Help me :(

Imran Rafiq Rather
  • 7,677
  • 1
  • 16
  • 35
  • 1
    `const`s don't become automatic globals, so `onload` doesn't find it. I'd recommend `document.addEventListener('DOMContentLoaded', bigBla)`. – deceze Dec 19 '20 at 10:09

1 Answers1

1

Try window.onload function in your javascript file.

window.onload = function() {
  bigBla();
};
Imran Rafiq Rather
  • 7,677
  • 1
  • 16
  • 35