0
const findNote = function(array, lookedUp) {
    const index = array.findIndex(function(note){
        return note.title === lookedUp
    })
    return array[index]
}

I get that the findNote function returns the lookedUp property if it exists but i don't understand how the note parameter gets the value we provide for the array parameter. We never provide an argument for the note parameter. Does the arguments provided for the findNote function automatically pass to findIndex?

blgotkn
  • 1
  • 1
  • Does this answer your question? [Where do the parameters in a javascript callback function come from?](https://stackoverflow.com/questions/34624634/where-do-the-parameters-in-a-javascript-callback-function-come-from) – Sebastian Simon Aug 25 '21 at 01:20
  • I understand that my question is exactly the same with the link you provided. Unfortunately i have alreay read the said link and i still can't understand the concept. I am stuck with this question: Does the second function gets its arguments from the call we make for the first function? The answer yes or no will make the whole concept "click" in my mind. – blgotkn Aug 25 '21 at 01:32
  • _You_ don’t call the callback function `function(note){ return note.title === lookedUp }`. _You_ don’t provide that argument. `Array.prototype.findIndex` does. Calling `array.findIndex` causes that method to call the callback function you provided; the method calls the callback function _with_ the argument. It just so happens that you don’t get to see the “code” of the method. You could also ask yourself, where the parameters `array` and `lookedUp` come from; but you _know_ that you call `findNote` yourself _with_ the two arguments. `findIndex` calls its callback, without you seeing it. – Sebastian Simon Aug 25 '21 at 01:39
  • Now it's all clear! I have been stuck on this for a while now. Thanks for the precise narration. – blgotkn Aug 25 '21 at 01:51

0 Answers0