0
function isBigEnough(value) {
  return value > 10;
}

const filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
// filtered is [12, 130, 44]

the above example from MDN would there have been any disadvantages? if we rewrite code as const filtered = [12, 5, 8, 130, 44].filter(x=>(x>10)); resulting in same output .a function expression way (ensures of course code would be more readable and hoisting not done).

samre ray
  • 49
  • 10
  • 2
    Biggest disadvantage is you (a) can't test the function in isolation, and (b) can't use the function anywhere else. Whether or not that's an **actual** disadvantage depends on context. – Dave Newton May 08 '23 at 21:02
  • 1
    Presumably a typo, but you have `>` vs `>=` in your two examples. In terms of inline arrow function vs named function, the main difference is the named function is reusable in other filters. – DBS May 08 '23 at 21:03

0 Answers0