3

I'm getting started with React and I'm wondering why they choose to use this notation:

const counter = (state, action) => {}

instead of the old-traditional:

function counter(state, action){}

I'm wondering if that's because of the const keyword. Because it is not possible to create a const function as it (as stated there: Are there constants in JavaScript?)

is that the only reason? I understand that const functions are important in React, to ensure the behavior isn't changed at runtime. But I wonder if that's the only reasons why they choose to use it.

Community
  • 1
  • 1
Vadorequest
  • 16,593
  • 24
  • 118
  • 215

1 Answers1

2

It is a personal choice, it is new ES2015 feature called arrow function,

const counter = (state, action) => { }

// you can also define counter like this
const counter = function (state, action) { }

The main difference is that arrow function does not have its own this and arguments

Oleksandr T.
  • 76,493
  • 17
  • 173
  • 144