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.

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.