JavaScript275 Documents

Arrow Function Only

In JavaScript and JSX files, use arrow functions and never use function declaration statements.

Correct

const getTitle = value => value.title
const getMessage = async value => value.message

Incorrect

function getTitle(value) {
    return value.title
}

Exceptions

  • Use a function declaration only when an external interface technically requires it.

Fix

Replace the function declaration with a const assigned to an arrow function, preserving async when applicable.