ghasemkiani avatar

Arrow Functinos in JavaScript

ghasemkiani

Published: 20 Oct 2017 › Updated: 20 Oct 2017Arrow Functinos in JavaScript

Arrow Functinos in JavaScript

Arrow functinos are a new syntax for functions in JavaScript. Here are a few examples:

    let f = (a, b) => {
        let c = 4;
        return a + b - c;
    };

    let g = x => x * x;

Due to their brevity, arrow functions make writing functions easier and more readable. However, it sould be noted that arrow functions are not just a syntactical sugar, they have important differences with norrmal functions. The most important difference is that they don't have a this binding separate from the outer scope. This makes them very useful, for example, for using with array functions, such as forEach, etc. Also, they don't have an arguments binding. To remedy this, you can use the rest parameter syntax (...rest).

Leave Arrow Functinos 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