0

I recently started to learn React native and I’ve seen some differences in function initialization

What is the difference between the old one (the one I used to use) function myFunction(){...} and the new one const myFunction = () => {...}

  • If not mistaken, I believe it's called ES6 Arrow Function. It's more convenient. – Ofir Baruch Jan 12 '21 at 10:46
  • The first one declares a function. The second one declares an anonymous lambda function and assigns it to the variable. They're pretty identical except that one is initialized on the script load and the other is when the line is executed. – John Jan 12 '21 at 10:46
  • 3
    @John — And they treat `arguments` differently. And they treat `this` differently. And one is hoisted and the other isn't. There are lots of differences. – Quentin Jan 12 '21 at 10:47
  • @OfirBaruch — It is not "more convenient". It works significantly differently. – Quentin Jan 12 '21 at 10:47
  • thank you all. Now I've figured out the answer. – João Ferreira Jan 12 '21 at 10:57

0 Answers0