what are the steps of the page building phases?
2. Executing JS code
What is the DOM?
It’s a structured representation of the HTML page in which every HTML element is represented as a node
what happens when the browser encounters the script tag while constructing the DOM?
the browser pauses the DOM construction from HTML code and starts executing JavaScript code
which is the primary global object that the browser exposes to the JS engine?
The primary global object that the browser exposes to the JavaScript engine is the window object
how does the browser keeps track of all the events that have occurred?
the browser uses an event queue
Describe the event handling loop
which are the 2 phases of the execution of a client app?
2. event handling
how many event can be processed at a time?
only one, JS in single threaded by default
In what order are events from the event queue processed?
In the same order in which they were triggered: the queue follows a FIFO logic
first in first out
what are the 3 most important ways that JS provides for the definition of a function
What are rest parameters?
Rest parameters enable us to reference the remaining arguments that don’t have matching parameter names.
which are the implicit function parameters?
The implicit function parameters are ‘this’ and ‘arguments’
What is the ‘this’ parameter?
The this parameter refers to an object that’s associated with the function invocation. For this reason, it’s often termed the function context.
How many ways are there for invoking a function in JS? List them and briefly describe them
There are 4 way:
What is the value of the ‘this’ object when invoking a function in the first simplest form => foo()
What’s the difference between function constructors and constructor functions?
A function constructor enables us to create functions from dynamically created strings. On the other hand, constructor functions, are functions that we use to create and initialize object instances.
what steps are triggered when using the keyword ‘new’ to call a function?
what happens when a constructor returns a value? what if that value is an object, e.g:
const puppet = {
rules: false;
}function Emperor() {
this.rules = true;
return puppet;
}does arrow functions has the “this” value?
No, Arrow functions pick up the value of the this parameter at the moment of their creation, the value of this is taken from the context.
explain the bind method
It’s a method that every functions have and creates a new function. This function has the same body, but its context is always bound to a certain object, regardless of the way we invoke it.
give the definition of scope
a scope refers to the visibility of identifiers in certain parts of a program. A scope is a part of the program in which a certain name is bound to a certain variable.
what’s the cost of a closure ?
Each function that accesses information via a closure has a “ball and chain” attached to it, carrying this information around.
So although closures are incredibly useful, they aren’t free of overhead. All that information needs to be held in memory until it’s absolutely clear to the JavaScript engine that it’s no longer needed (and is safe to garbage-collect), or until the page unloads.
what the difference between function context and execution context?
function context is the object on which our function is invoked, which can be accessed through the this keyword. An execution context, although it has a similar name, is a completely different thing. It’s an internal JavaScript concept that the JavaScript engine uses to track the execution of our functions.
what is a lexical environment?
A lexical environment is an internal JavaScript engine construct used to keep track of the mapping from identifiers to specific variables