0

What is the meaning of below statement/code?

Console.log(x=>x*(y=>y*2)(2))(2) //output is 8 What's the meaning of '=>' ?

18th Apr 2022, 5:15 AM
King
King - avatar
2 Respuestas
+ 1
18th Apr 2022, 6:00 AM
Ipang
+ 1
We have the expression (x=>(y=>y*2)(2))(2). We start from the inside and work our way out: y=>y*2 is a function which multiples its argument y by 2. Adding (2) at the end of this function means to call it with the argument 2. (Look up anonymous functions amd closures). (y=>y*2)(2) is therefore equal to 4. We are left with: (x=>x*4)(2) x=>x*4 is a function which multiples the argument by 4. (2) means to call this funcyion with the argument 2. The result is thus 2*4=8
20th Apr 2022, 4:57 AM
John Doe