Menu
Coddy logo textTech

The Arrow Functions

Lesson 4 of 9 in Coddy's Tricky parts of Modern Javascript (ES6+) course.

A simple and concise way of creating functions is an Arrow Function.

The syntax of arrow function is 

let func = (arg1,arg2,...,argN) => {
    // function body
}	

This function can be called exactly similar to a normal function ex. func(val1,val2,...,valN)

When function has only single parameter , it can be written in more simple way as ex. 

let square = num => num*num;

here we don't require the parenthesis for the function parameters.

While creating single line functions like above, we can omit return keyword for simplicity.

Best use cases of arrow functions:

  • Simple functions
  • Callbacks
  • Arrow functions don't have their own this , so use them where you don't require this .
challenge icon

Challenge

Easy

Write an arrow function toCelsius that converts temperature Fahrenheit to Celsius. (Result should be two digits after decimal)

to convert temperature from Fahrenheit to Celsius, use below formula: 

Celsius = (5/9) * (Fahrenheit-32)

Try it yourself

All lessons in Tricky parts of Modern Javascript (ES6+)