0

Code example:

function unusedDigits(...args){
  return [0,1,2,3,4,5,6,7,8,9].filter(o => args.join("").indexOf(o) === -1).join("")
}

Everything is clear here. Exept =>. What does this mean in javascript?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
FreeLightman
  • 2,224
  • 2
  • 27
  • 42
  • 1
    An arrow function expression (also known as fat arrow function) has a shorter syntax compared to function expressions and lexically binds the this value. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions – Tom Yates Oct 11 '15 at 22:10
  • This is the new ES6 (EcmaScript 6, the new upcoming Javascript version) syntax for functions, known as Arrow Functions, which are specially useful when used for Functional Programming. Just last month I have written an article about how do they work: https://www.airpair.com/javascript/posts/mastering-es6-higher-order-functions-for-arrays#es6-arrow-notation-101 – Tiago Romero Garcia Oct 11 '15 at 22:21
  • Strange. Even now I cannot find this question using search. Does stackoverflow understand '=>' ? Similarly, I could not find this in google. Or is there a way for finding with such symbols? – FreeLightman Oct 12 '15 at 04:58

1 Answers1

2

This is a ES6 arrow function which is a short syntax for function expression. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

So:

// ES5
var selected = [0,1,2,3,4,5,6,7,8,9].filter(function (o) {
   return args.join("").indexOf(o) === -1;
});

// ES6
var selected = [0,1,2,3,4,5,6,7,8,9].filter(o => args.join("").indexOf(o) === -1);
UserNeD
  • 1,409
  • 13
  • 14