0

I have this code that works in Chrome, but doesn't work as expected in Safari:

if (typeof myFunction !== 'function') {

  function myFunction() {
    console.log('myFunction invoked');
  }

  myFunction();

} else {
  console.log('myFunction ALREADY DEFINED o_O!');
}

When I run this code in Chrome – it logs "myFunction invoked".

When I run it in Safari – it logs "myFunction ALREADY DEFINED o_O!"

I want to make typeof work in Safari the same as in Chrome. How can I achieve it?

1 Answers1

0

just use the below code :

if (typeof myFunction !== 'function') {

  let myFunction = function() {
    console.log('myFunction invoked');
  }

  myFunction();

} else {
  console.log('myFunction ALREADY DEFINED o_O!');
}

let keyword will fix your problem

Milad Bonakdar
  • 273
  • 2
  • 16