Jeremy Troy Suchanski
Web Frontend Development II
Gary James
May 16, 2022
L10 Readings Notes
An Introduction to Functions, Execution Context and the Call Stack (Notes)
- JavaScript Execution: One thing at a time: single threaded execution – line by line in order: synchronous. Does 2 main things #1 stores things in memory #2 executes the code.
- Execution context: A space in which to execute our code (memory & execution thread)
- Global execution context: the whole application code.
- Global variable environment: global memory.
- Functions: a way of wrapping up some instructions or code to be done later on with a label. When run they have a #1 local execution context and a #2 local memory (variable environment). Then it returns a value to the global execution context’s memory.
- Variables equal to a function: default to undefined at first, until code is executed.
- Parameter: a placeholder to allow different values to be run in the code.
- Argument: the actual value that gets put into a function’s parameter.
- JavaScript call stack: A stack of calls to functions - where it is, where it was, where it is going to next. Global context is always 1st and on the bottom.
- Push: something added to the call stack.
- Pop: remove the top item from the stack.
How to Understand Callbacks & Higher Order Functions
- Generic function: making functions generic makes them reusable and useful. This is the essence of why we have higher order functions.
- Higher Order Functions: (map, filter, reduce) There is not only some data we don’t want to determine ahead of time, but also some functionality. It is any function that takes in a “baby” function or returns out a function. They keep our code DRY and let us run asynchronous code.
- DRY: Don’t repeat yourself.
- Callback: is the function passed into a function, passing in some functionality through a function to a function through a parameter.
- Functions: are 1st class objects meaning that they get treated like any other object in JavaScript #1 assigned to variables and properties of other objects #2 passed as arguments into functions. #3 returned as values from functions. They have one property that objects don’t have – they can be invoked/called/run.