# Node.js - why is the callback getting passed redundant-looking arguments?

**URL:** <https://forum.freecodecamp.org/t/node-js-why-is-the-callback-getting-passed-redundant-looking-arguments/62283>\
**Category:** General\
**Created:** [December 5, 2016, 5:01pm UTC](https://forum.freecodecamp.org/t/node-js-why-is-the-callback-getting-passed-redundant-looking-arguments/62283 "2016-12-05T17:01:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![olddognewtrix123](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/olddognewtrix123/32/33588_2.png) [@olddognewtrix123](https://forum.freecodecamp.org/u/olddognewtrix123)\
**Post date:** [December 5, 2016, 5:01pm UTC](https://forum.freecodecamp.org/t/node-js-why-is-the-callback-getting-passed-redundant-looking-arguments/62283/1 "2016-12-05T17:01:47Z")

</div>

Why, on line 23 below, does getFiles get passed the filterStr? I see how filterStr gets used higher up in the .filter fuction. But if list is already populated during fs.readdir, why does the callback further down need filterStr again? I guess the same could be asked about dir as well. I just see getFiles either returning an error or printing the contents of list to the console.

```
var fs = require('fs')
var path = require('path')

var dir = process.argv[2] // '/tmp/_learnyounode_2995'
var filterStr = process.argv[3] // "md"

function getFiles(dir, filterStr, callback) { 

  fs.readdir(dir, function (err, list) {  
    if (err)
      return callback(err)

    list = list.filter(function (file) {
      return path.extname(file) === '.' + filterStr
    })

    callback(null, list)  
  })
}

getFiles(dir, filterStr, function (err, list) {
  if (err)
    return console.error('There was an error:', err)

  list.forEach(function (file) {
    console.log(file)
  })

```

})

---

<div class="post-metadata">

**Author:** ![Omegga](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/omegga/32/97940_2.png) [@Omegga](https://forum.freecodecamp.org/u/Omegga)\
**Post date:** [December 5, 2016, 5:10pm UTC](https://forum.freecodecamp.org/t/node-js-why-is-the-callback-getting-passed-redundant-looking-arguments/62283/2 "2016-12-05T17:10:50Z")

</div>

They don’t get used twice.It just happens that variables have the same name as parameters in the function definition.The function doesn’t get invoked until line 23

---

<div class="post-metadata">

**Author:** ![olddognewtrix123](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/olddognewtrix123/32/33588_2.png) [@olddognewtrix123](https://forum.freecodecamp.org/u/olddognewtrix123)\
**Post date:** [December 5, 2016, 5:26pm UTC](https://forum.freecodecamp.org/t/node-js-why-is-the-callback-getting-passed-redundant-looking-arguments/62283/3 "2016-12-05T17:26:29Z")

</div>

Oh, of course.

```
// Here I declare my variable(s)
//Here I define my function(s)
//Here I invoke my (first) function

```

Not sure why I wasn’t getting that at first.

Thanks!

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [January 16, 2021, 6:10am UTC](https://forum.freecodecamp.org/t/node-js-why-is-the-callback-getting-passed-redundant-looking-arguments/62283/4 "2021-01-16T06:10:18Z")

</div>


