Week 3 Flashcards
(106 cards)
what is a template literal
a new way to create a string literal that expands on the syntax of the String primitive type allowing for interpolated expressions to be inserted easily into strings.
what is the main advantage of using template literals?
the ability to interpolate variables or expressions into strings
what do we wrap the data that we want to interpolate in?
${}
what happens to the data wrapped in the dollar sign curly braces when the code is run?
the variables or expressions wrapped within the ${} will be evaluated and then replaced with the value of that variable or expression
what character do we use to create a template literal?
a backtick aka grave (`)
what can template literals evalute?
anything that can be stored in a variable including functions
what is a call stack?
a structure that JAvaScript uses in the JS runtime to keep track of the evaluation of function calls; it uses the stack data structure
what is a stack? how are we using this right now?
a general pattern of organizing a collection of items
currently the items being organized are the function calls that occur during the execution of our program
describe our current usage of a stack as a vertical pile
- pushing a new item to the stack - new items must be placed on top of the pile
- popping the top item from the stack - at any point, the only item that can be removed is the top of the pile
what does the term stack frames describe?
the items that are being pushed and popped; items placed on the call stack
describe the ways the JS leverages stack mechanics during runtime
- when a function is called, a new frame is pushed onto the stack
- when a function returns, the frame on the top of the stack is popped off the stack
when will a frame entirely leave the stack
when the function is popped due to a function return which can either be an explicit return with the return keyword or an implicit return after the last line of the function’s definition is executed
what does the function on top of the call stack represent?
the function being executed currently
when can the program on the call stack exit?
when the stack is empty
why is JS a single-threaded language?
the use of a single call stack leads to a single thread of execution; the JS runtime can only preform one command at a time and the one command currently being executed is what ever is at the top of the stack
what is the critical behavior to be aware of in the JS runtime?
an event can only be handled once the call stack is empty
what does it mean for a function to be recursive?
the function is called from within itself
what is the difference between a functtion that recurs and a function that is recursive
recur means for a function to be called more than once, while recursive means that the function is called from within itself
what are the two cases in a recurisve function and what does this term mena?
the two cases are the expected output for a particular input in a resursive function; the two cases are the base case and the recursive case
what is the base case in recursion?
when the data passed into our function is processed without any additional recursion; the base case is excuted, the function runs once and ends; the situation in which the function stops recursing
what is the base case also know as? and why
the terminating case because it results in the function stopping
what is the recursive case?
the situation where the function recurses, this represents the data state that causes the function to call itself; what causes our function to keep recursing
what is a default parameter?
I’m not sure yet
how is a default parameter declared?
it is declared in the function signature like a regular parameter, except it is given a default value using =