The Journey of #100DaysOfCode (@Tala_Hareb)

Hey everyone!

I’m taking on the #100DayCodeChallenge!

Over the next 100 days, I’ll be sharing my journey, knowledge, and experiences.

Stay tuned for regular updates!

3 Likes

Day 1:

Today I learned about “Promises” in JS.

Definitions :

  • Promises : A way to handle asynchronous operations. ( put simply: They represent a value that might be available now, in the future, or never. ) => formally noted as pending, fulfilled, or rejected.
  • Asynchronous operations : Allow a task to start, continue doing other things, and then finish later. They don’t block or stop the program from running other code in the meantime.

Initializing a Promise :

  • using const : const = constant. Use const when you know you won’t change the promise.
  • using let : let = let this variable change if needed. Use let when you think you might need to change the promise to something else.

3 Likes

Day 2:

Arrow Functions:

When to use:

  • For quick, simple functions.
  • To ensure this is lexically scoped, especially in callbacks: Like a robot that remembers its owner even if told to do something later.
  • When you don’t need a function with its own arguments or this context: Like a robot doing a simple task without needing extra tools.

When not to use:

  • When creating a constructor function.
  • If this needs to be dynamic within the function: Like a robot that can change its owner based on who is using it.
  • If you need the arguments object: Like a robot that needs to know information outside the task to complete the assigned task.

Summary

  • Use arrow functions when you have simple tasks that don’t need special tools or changing owners.
  • Don’t use arrow functions when you need to see all the arguments or change the robot’s owner (this).

3 Likes