Build a Todo App using Local Storage - Step 40

Tell us what’s happening:

I don’t understand why this code works. Here, addOrUpdateTask is declared above updateTaskContainer, but it uses updateTaskContainer. This can only work with function declarations. Or am I wrong?

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

          <button type="button" class="btn">Edit</button>
          <button type="button" class="btn">Delete</button> 
          ///

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36

Challenge Information:

Build a Todo App using Local Storage - Step 40

updateTaskContainer is a function, you may want to review the lesson that introduces arrow functions: https://www.freecodecamp.org/learn/full-stack-developer/lecture-working-with-functions/what-are-arrow-functions-and-how-do-they-work

I understand that this is a function. What I mean is that only a declarative function can be used before it is declared.

and that depends on when updateTaskContainer is executed, not in order of declaration, as long as addOrUpdateTask exists once updateTaskContainer executes, then everything works as intended

Do you mean that updateTaskContainer()
reset() are considered to be called at the same time as addOrUpdateTask, since they are called inside addOrUpdateTask?

it’s not exactly at the same time, but when addOrUpdateTask is called, those will be called by consequence as there are function calls to those functions inside addOrUpdateTask

and then, since the functions are created when the app loads, but are called only when the button is clicked, the functions all exist at that point, so there is no issue with the order of declaration

Got it, for some reason I took it literally. That you can’t write a function call before its declaration.

you can’t, but the order in which you see the lines, and the order in which the lines are executed is often not the same, and to the code it’s order of execution that matters