ghasemkiani avatar

Function Name in Arrow Functions in JavaScript

ghasemkiani

Published: 21 Oct 2017 › Updated: 21 Oct 2017Function Name in Arrow Functions in JavaScript

Function Name in Arrow Functions in JavaScript

The function name is an important bit of information, especially for debugging. But, how is it determined in arrow function syntax?

For normal functions, function name is clearly stated in function declarations:

    function doSomething() {
        // body code
    }

Even for function expressions, you can supply a function name to make debugging easier:

    var f = function doSomething() {
        // body code
    };

Arrow functions do not use the function keyword and you cannot include a function name. But since they are essentially used in expressions, the left-hand side variable name is assigned to the resultant function as the function's name property.

    let doSomething = () => {
        // body code
    };

This is the standard behavior according to the specification.

Leave Function Name in Arrow Functions in JavaScript to:

Written by

Read more #technology posts


Best Posts From ghasemkiani

We have not curated any of ghasemkiani's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From ghasemkiani