Vocabulary / Terms Flashcards
(40 cards)
Execution Context
The execution context is the environment in which a JavaScript function is being executed. Each execution context has its own variable scope.
Whenever a function is invoked, a new execution context is pushed onto the call stack, and a new variable environment is created along with it. The function’s code runs in the new execution context and has access to the variable environment in the execution context directly below that new execution context (the one in which the function was invoked).
Upon exit of the function, the execution context is popped off of the call stack. Code in one execution context is stopped until the code in the execution context above it finishes running.
Scope
What data is available at any given time… or:
Variable environments (or local memories) are commonly referred to as “scope.” While each execution context is stacked on top of the execution context preceding it, each scope is created inside of the previous scope. Code being executed inside a scope not only has access to the variables in that scope, but also the variables in all the scopes that encase it. Therefore, code that runs in a given execution context has access to all the variables created in the execution contexts below it.
What is a closure?
A closure is a variable environment that has outlived its execution context and remains attached to a function that also has outlived the same execution context.
If multiple functions are created in the same execution context and all of them outlive that execution context, those functions each have their own closure, and each of these closures will access the same variables in memory. Therefore, mutation of those variables by one of those functions will affect the other functions in the manner that they will be accessing the same (mutated) variables.
Names for closure data
- Persistent Lexical Scope Referenced Data
- C.O.V.E. - Closed Over Variable Environment
- Closure
- Backpack
Method
A function attached to an object
Parameter
A variable that will have a value passed into a function
Argument
Value of a parameter passed into a function
Declare
Creating (and naming) a thing in memory (like a variable or function) . This is different from defining, as you can declare a variable without giving it a value (which would be defining it)
Define or Assignment
Giving a value to a variable or function. Can be used to mean Declare + Define if you are creating a variable or function and giving it a value.
Initialize
When you declare a variable it is automatically initialized, which means memory is allocated for the variable by the JavaScript engine.
Describe this: const test = addTwo(5);
Declaring a variable test, and assigning it to the evaluated result of the addTwo function, with the argument 5 passed in as its parameter.
Implicit Parameter
this.whatever (this)
When a function is invoked, with the explicitly defined parameters that represents the argument, an implicit parameter this is also passed. The this parameter refers to the object that invoked the function. This is why this parameter is also known as function context.
function myFunc() { return this; } myFunc();
“Left of the dot rule”
poop.function() { this.val = 3 }
“this” equals whatever is left of the dot
In this example: this === poop
Constructor Functions
Functions made with the “new” keyword.
A constructor is a special function that creates and initializes an object instance of a class. In JavaScript, a constructor gets called when an object is created using the new keyword. The purpose of a constructor is to create a new object and set values for any existing object properties.
The following example defines a constructor function called Person:
function Person(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; }
let person = new Person('John','Doe'); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Basically, the new operator does the following:
Create a new empty object and assign it to the this variable.
Assign the arguments ‘John’ and ‘Doe’ to the firstName and lastName properties of the object.
Return the this value.
It’s functionally equivalent to the following:
function Person(firstName, lastName) { this = {};
// add properties to this this. firstName = firstName; this. lastName = lastName; return this; }
Function Label
The assigned name or label of a function stored in memory. This points to the function definition.
Function Definition
The code / meat of a function stored in memory. The function label points to this.
Thread
line by line of code in current execution context.
Some uses of closure
storing data outside the global environment
memorize calculations
once-afy a function
Dunder Proto __proto__
This is the name of the “bond” that links an object to it’s prototype.
Every object in JS has this property.
It points back to the prototype object of the constructor function that created that object.
The __proto__ property of Object.prototype is an accessor property (a getter function and a setter function) that exposes the internal [[Prototype]] (either an object or null) of the object through which it is accessed.
Lexical Scope
What data was originally available at the birth of a function.
Callback
A function passed as an argument to another function.
Anonymous funciton
A function with no label in memory
Base Case
Case where recursion is broken
Side Effect
Side effects are reactions from actions performed in a function.
EX:
• Writing to console
• Drawing or writing to screen
• Modifying an external or global property