akshansh
akshansh

Reputation: 21

What's the meaning of JavaScript in below?

l = (m, n) => { if (w()) return n-1;} is one of a sample code but I want to understand the use of this in a JavaScript I have a long code which has most use of these elements can anyone help me out on this really confused on this part.

I have tried on https://www.w3schools.com/js/js_arrow_function.asp but could not get exact answers.

I have tried on some forums too but the exact search results could not be fetched.

Upvotes: 0

Views: 128

Answers (1)

stud3nt
stud3nt

Reputation: 2143

=> stands for arrow function which was introduced in ES6.

So instead of typing below syntax for writing function:

function test(m, n) {
    if (w()) return n-1;
}

The same can be written using arrow function:

(m, n) => {
    if (w()) return n-1;
}

In your code snippet, variable l is assigned the value of above function. Your function will return n-1 based on the return of another function w().

Upvotes: 1

Related Questions