-1

I have seen many examples of Promises but not able to understand meaning of "xyz(()=>{" in codes. Sometimes there are two equal signs in same line. Please help me understand. Also, along with that please drop a link from where I can easily learn javascript for LWC.

Thanks!

  • "Sometimes there are two equal signs in same line." Can you provide an example? – rb612 Sep 28 '22 at 05:21
  • Does this answer your question? [What's the meaning of "=>" (an arrow formed from equals & greater than) in JavaScript?](https://stackoverflow.com/questions/24900875/whats-the-meaning-of-an-arrow-formed-from-equals-greater-than-in-javas) – PeterJames Sep 28 '22 at 06:45
  • @rb612 check this video timeframe https://youtu.be/h33Srr5J9nY?t=129 – beardsandlaughter Sep 28 '22 at 09:48

2 Answers2

0

() => { } is An arrow function expression whitch is a compact alternative to a traditional function expression. where () contains params and {} contains the execution code.

new Promise((resolve, reject) => {
    // code here
    }); 

above code is same as

new Promise(function () {
      // code here
});

read this doc for more info.

Storytellerr
  • 642
  • 3
  • 18
0

If you're moving from "old school" JavaScript or Aura components to LWC this trailhead might help: https://trailhead.salesforce.com/content/learn/trails/learn-to-work-with-javascript

It'll explain that it's not really LWC that comes up with all these new toys, any decent ES6 (JavaScript spec from 2015 onwards) tutorial should help you.

I've also found the MDN resource for arrow functions to be pretty cool. The code blocks go step by step like some math proof.

eyescream
  • 18,088
  • 2
  • 34
  • 46