DEV Community

Discussion on: Level Up with JavaScript

Collapse
 
loicboset profile image
Loïc Boset

Thanks for your article!

Is there a difference between this

function greetMe(yourName) { 
    alert("Hello " + yourName); 
} 
Enter fullscreen mode Exit fullscreen mode

and this

const greetMe = (yourName) => alert("Hello " + yourName)
Enter fullscreen mode Exit fullscreen mode

or is the completely equivalent?

Collapse
 
alexander89 profile image
Alexander Halemba • Edited

They are different. For example, "functions" have a "this" pointer. Fat arrow functions try to find "this" in the scope.

I try to avoid "funtions" whenever I can.

Collapse
 
devcronin profile image
DevCronin

Thank you for replying!

Collapse
 
loicboset profile image
Loïc Boset

Thank you!

Collapse
 
devcronin profile image
DevCronin

Exactly what Alexander said. In addition let and var can be used. It is most common preactice now to use let and const though. I will be digging deeper into the different types later in the blog series. For now though, const is used to create a variable that can not be changed. Var can be changed anywhere. Let can be changed in the Block scope of the function.

Collapse
 
loicboset profile image
Loïc Boset

Thanks!