JS advance Flashcards

1
Q

What does this code do?
const wrap = value => () => value;

A

return a function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What allows JavaScript functions to “remember” values from their surroundings?

A

closures

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is this?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is event loop?

A

Built-in libuv (library) mechanism called the event loop, which handles the execution of asynchronous functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are closures?

A

Closures is when a function remembers and continue to access variable from outside its scope, even when the function is executed in different scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is promise object?

A

The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is async/await?

A

The async/await keywords enable asynchronous, promise-based behavior to be written in a cleaner style.
It’s alternative to .then method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

shallow/deep copy

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are Classes in JavaScript?

A

Classes are custom data structures (objects) that includes both data and behaviors that operate on that data.
Typeof Class is a function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does JavaScript runtime environment mean.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Restful API?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does script mean?

A

In computer programming, a script is a program or sequence of instructions that is interpreted by another program rather than by the computer processor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Solution Stack

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is hoisting in JS?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Event Delegation pattern?

A

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’)
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What does Block Scoping mean?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is event bubbling?

A

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.

19
Q

What does Lexically mean?

A

The place where item (for example variable) got created. Definition area of an expression.

20
Q

What is the execution context?

A

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.

21
Q

What is req, res object?

A

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.

22
Q

What is function constructor?

A

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’);

23
Q

What is prototypal inheritance?

A

Prototypical inheritance refers to the ability to access object’s properties from another object.

24
Q

What is ‘Strict Mode’

A

Strict Mode let as use restricted variant of JavaScript. For example x = 3.14; will throw error cause x wasn’t declare.

25
Q

What does ‘New’ operator do in JavaScript?

A

The new operator creates an instance of a user-defined object type or one of the built-in object types that has a constructor function”

26
Q

What are 4 pillars of OOP in JavaScript

A

Abstraction - hide away the implementation details inside something e.g inside functions.
Encapsulation - Removing access to parts of your code and making things private (is exactly known as data hiding)
Inheritance - lets one object acquire the properties and methods of another object. In JS Prototypal inheritance. Reusability is main benefit.
Polymorphism - the condition of occurring in several different forms.

27
Q

What’s the difference between linear and binary search in JS

A

Linear search is a search that finds an element in the list by searching the element sequentially until the element is found in the list. On the other hand, a binary search is a search that finds the middle element in the list recursively until the middle element is matched with a searched element.

28
Q

What is O-Big-Notation?

A

Big O notation is used to describe how an algorithm performs when the input size grows.

29
Q

What does compilation mean?

A

The process of converting high level programming language into machine language that computer can “understand”. In general it has 3 basic stages.
1) Tokenizing/Lexing - breaking up strings of characters into meaningful chunks. var a = 2 will be broken into var, a, = and 2.
2) Parsing- taking a stream (array) of tokens and turning it into a tree of nested elements which will represents structure of the program. This is called AST (Abstract Syntax Tree)
3) Code generation - Taking AST and turn it into executable code.

30
Q

What does global scope mean?

A

It’s a scope which contains and is visible in all other scopes.

31
Q

What does shadowing mean?

A

If you have variable in global (or outer scope) which has the same name like variable inside inner scope, it is impossible to access variable from outer scope. Inner variable will “shadow” outer one. You can go around using window.name (name as variable name )

32
Q

What are types in JavaScript

A

?

33
Q

What are the “falsy” values in JavaScript?

A

Undefined, Null, “”,+0,-0,NaN,False. If any avalue

34
Q

Logical AND && operator. How does it work?

A

&& operator let as do quick evaluation. It returns value of one of the specified operands. JS will coerce first value by using Boolean(<first>). If returns not "falsy" value it will return which is on the right hand side.</first>

35
Q

What does short-circuit mean in JS?

A

In the context of logical operations in programming, “short-circuiting” refers to the process where the evaluation of the entire expression stops as soon as the outcome is determined.

Take logical AND (&&) as an example:

expression1 && expression2 <- if the expression1 is false JS knows that entire expression is false without evaluating second expression.

36
Q

What is implicit coercion in JS?

A

In JS implicit coercion refers to automatic conversion values to one type to another. console.log(‘5’ + 3); // “53” Another example is when non-Boolean values are used in context that requires a Boolean like “if” statement.

37
Q

What is explicit coercion in JS?

A

Explicit coercion means that we intentionally change value type. var a = 123 var b = String(a).

38
Q

What is optional chaining operator “?.”

A

”?.” optional chaining operator allows safe access to nested object properties by checking each reference in the chain, making sure it’s not null or undefined before accessing the next property.
let user = {
name: “John”,
address: {
street: “123 Main St.”,
city: “Anytown”
}
};
console.log(user?.phone?.number); // Outputs: undefined, no error
JavaScript sees that user.phone is undefined and does not attempt to access number. Basically the expression short-circuits and returns undefined without throwing an error.

39
Q

What are three states of Promise?

A

Pending - initial state, neither fulfilled nor rejected,
Fulfilled - operation was successful
Rejected - operation failed

40
Q

How is the value of this determined in an arrow function?

A

In JavaScript, the value of this within an arrow function is determined by the surrounding lexical context where the arrow function is defined, not where it is called

41
Q

What is Webpack?

A

In short - It’s module bundler. It bundles JavaScript files.
In not so short - Bundling: Webpack processes your application by starting from one or more entry points and then tracking down all the direct and indirect dependencies, bundling them into one or several files. This is especially useful in a modern web development environment where your application might consist of hundreds of different modules and dependencies. Webpack can bundle all these into a few bundles or even a single bundle, making it easier and faster for browsers to load your application.

Transformation: Webpack can transform the bundled files in various ways. For example, it can convert TypeScript to JavaScript, SASS to CSS, and shrink the size of the files through minification. It does this with the help of loaders and plugins. Loaders in Webpack transform the source code of a module, while plugins are used to perform a broader range of tasks like bundle optimization, asset management, and environment variable injection.

42
Q

What is apply() method used for?

A

The apply() method in JavaScript is used to call a function with a given this value and arguments provided as an array (or an array-like object).

43
Q

What is call() method used for?

A

The call() method in JavaScript is used to call a function with a specific this value and individual arguments. The first argument is used to set the this context, and subsequent arguments are passed to the function as they are.

44
Q

What is bind() method used for?

A

Certainly! The bind() method in JavaScript creates a new function that, when called, has its this keyword set to the provided value. Essentially, bind() allows you to preset the this context and initial arguments of a function, returning a new function with these bindings fixed.