JS advance Flashcards
What does this code do?
const wrap = value => () => value;
return a function
In JavaScript, when is a function’s scope determined; when it is called or when it is defined?
JS function scope is determined when we call a function. This is because JavaScript uses a feature called “lexical scoping” or “static scoping,” where the scope of a function is based on its location in the source code when it is invoked.
What allows JavaScript functions to “remember” values from their surroundings?
closures
What is this?
This keyword is a reference to the object which is executing current function.
If use regular function method on object this is going to refer to global object!
In strict mode it will be undefined.
Arrow functions does not create its own execution context but inherits the this from the outer function where the arrow function is defined.
The value of this depends on how and where a function is called, and it can change dynamically during runtime.
What is event loop?
Built-in libuv (library) mechanism called the event loop, which handles the execution of asynchronous functions.
What are closures?
Closures is when a function remembers and continue to access variable from outside its scope, even when the function is executed in different scope.
What is promise object?
The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
What is async/await?
The async/await keywords enable asynchronous, promise-based behavior to be written in a cleaner style.
It’s alternative to .then method.
shallow/deep copy
A deep copying means that value of the new variable is disconnected from the original variable while a shallow copy means that some values are still connected to the original variable. by Reference
What are Classes in JavaScript?
Classes are custom data structures (objects) that includes both data and behaviors that operate on that data.
Typeof Class is a function.
What does JavaScript runtime environment mean.
JavaScript runtime environment refers to where your program is being executed. Might be executed in browser or Node.js. Front-end JavaScript aps are executed in browser and have access to window object. Back-end JavaScript aps are executed in the Node environment and have access to the file system, databases, and networks attached to the server.
What is Restful API?
A RESTful API is an interface that two computer systems use to exchange information securely over the Internet.
A REST stands for Representational State Transfer.
What does script mean?
In computer programming, a script is a program or sequence of instructions that is interpreted by another program rather than by the computer processor.
Solution Stack
In computing, a solution stack or software stack is a set of software subsystems or components needed to create a complete platform such that no additional software is needed to support applications.
What is hoisting in JS?
Hosting is JavaScript’s default behavior of moving all functions and declarations “to the top” of the current scope prior to execution of the code. Let, const and arrow functions are hoisted but they are not initialized as undefined.
What is Event Delegation pattern?
We add one event listener to a parent element. And then we can execute different functions base on which children element was clicked (which tagName) This works because event bubbling.
let birds = document.querySelectorAll(‘li’)
for( const bird of birds) {
if (bird.matches(‘.endangered’)) {
console.log(‘whee’)
}
}
What does Block Scoping mean?
The Block Scope is a set or rules that manages the accessibility and visibility of variables.
Block scope is useful for creating variables or constants that are only needed within a specific block of code, and it helps to prevent unintentional pollution of the global scope or unintended reassignments of variables.
Block Scoping determines where we can access particular variables or functions. Let and const scope is defined lexically by a block ( curly braces {} ,for, while, if statement) and they provide block-scoping.
A code block does not create a scope for var variables, but a function body does
A code block in JavaScript defines a scope for variables declared using let and const:
The inner scope can access the variables of its outer scope.
What is event bubbling?
Event Bubbling is a concept in the DOM (Document Object Model). It happens when a element receives an event, and that event bubbles up (or you can say, is transmitted or propagated) to its parent and ancestor elements in the DOM tree until it gets to the root element
OR
Order in which event handlers are called when one element is nested inside a second element and both registered a listener for the same event.
What does Lexically mean?
The place where item (for example variable) got created. Definition area of an expression.
What is the execution context?
The Execution Context contains the code that’s currently running, and everything that aids in its execution. It’s a wrapper to manage the code. During the Execution Context run-time, the specific code gets parsed by a parser, the variables and functions are stored in memory, executable byte-code gets generated, and the code gets executed.
What is req, res object?
The req object represents the HTTP request and has properties for the request query string, parameters, body, and HTTP headers. The res object represents the HTTP response that an Express app sends when it gets an HTTP request.
What is function constructor?
Functions Constructors let as create multiple similar objects. We define ‘this’ within function e.g this.name = name (where name is a parameter for a function) And then we use function name and a new keyword. Which will create empty object and assign ‘this’ to it.
//function constructor
function Person (name) {
this.name = name
this.age = 45
}
// create an object
const person = new Person(‘Max’);
What is prototypal inheritance?
Prototypical inheritance refers to the ability to access object’s properties from another object.
What is ‘Strict Mode’
Strict Mode let as use restricted variant of JavaScript. For example x = 3.14; will throw error cause x wasn’t declare.