JavaScript Arrow Function: Every JavaScript Developer must know.

Rhea RB
2 min readNov 18, 2022

--

What is Arrow Function ?
An arrow function expression is a way to declare function in JavaScript.
It was introduced in 2015 (ES6), which is why it’s also known as the ES6 function.

Syntax
The syntax has an arrow in it hence the name “Arrow Function”.

Here is the syntax for writing the ES6 function. You don’t need to use the function keyword.

The difference.

Let’s understand the difference between the normal and ES6 function.

We can’t call the function before declaring it.

In the ES6 function, this refers to the scope where the function is present.
Whereas, in case of normal, it inherits that from the parent scope.

In the normal function, when we say obj.HasThis the this keyword is changed to obj.

In case of arrow functions, there is no such thing. It takes this value from the parent context.

In the previous example, the parent context was window, but if we make a nested function under hasThis it will return the obj as this value.

This is because in that case, hasThis will be the parent context.

Last words
These are few of the many difference. We have to use the appropriate one depending on the use case.

If you liked my blog, please do follow me : Rhea RB

Thank you for reading ! Happy Coding !!

--

--

Rhea RB
Rhea RB

Written by Rhea RB

Hello ! I am a senior software engineer, passionate about tech and product.

No responses yet