2. Flashcards

Linkedin

1
Q

Why is it usually better to work with Objects instead of Arrays to store a collection of records?

A

Most operations involve looking up a record, and objects can do that better than arrays.

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

What is a closure?

A

Closure is a function in a function. The inner function has access to the outer’s function scope and parameters even after the outer function has returned.

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

What are the differences between call, apply, and bind?

A

call and apply immediately calls a function while bind creates a new function that can be invoked in the future. Arguments with call are passed in one by one, separated with a comma while apply expects an array as its argument.

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

What is an event loop?

A

An event loop is responsible for executing javascript code, collecting and processing events, and executing queued sub-tasks.

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

What is currying function?

A

A currying function is the process of taking a function with multiple arguments and turning it into a sequence of functions each with a single argument.

Curried functions are a great way to improve code reusability and functional composition

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

What is prototype in javascript?

A

Prototypes are the mechanism by which JavaScript objects inherit from another object.

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

What is memoization?

A

Memoization is an optimization technique by storing the result of expensive function calls and returning the cached results when the same inputs occur again.

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

What is a higher-order function?

A

a higher-order function is a function that accepts another function as an argument or returns a function as a return value or both of them.

Map, filter and reduce are some examples of higher-order functions that are already built-in to JavaScript.

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

What is event delegation?

A

Event delegation is a pattern of adding a single event listener to a parent element instead of multiple elements.

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

Name some ways to handle asynchronous operation in javascript.

A

Callback is a function that is used to notify the calling instance.

Promise is an object representing the eventual completion or failure of an asynchronous operation. A pending promise can either be fulfilled with a value or rejected with a reason.
Callbacks are attached to the returned promises that make handling of asynchronous code easier and more readable.

async/await is a new addition to ES2017 which is syntactic sugar on top of promises and make asynchronous code look synchronous code.

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

What is recursion?

A

Recursion is a technique for iterating over an operation by having a function call itself repeatedly until it arrives at a result.

This is most effective for solving problems like sorting or traversing the nodes of complex or non-linear data structures.

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

What is Javascript?

A

it is the scripting language of the web that was initially intended to run on the browser. Today, JavaScript is used in the server.

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

What is ECMAScript?

A

is a standard specification for scripting languages. JavaScript is based on ECMAScript.

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

What is the difference between == and ===?

A
== compares values
=== compares both type and value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a promise?

A

is an object that may produce a single value sometime in the future with either a resolved value or a reason for not being resolved

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

What is strict mode in JS?

A

it is useful for writing secure JS code. It prevents some bugs from happening and throws more exceptions.

17
Q

What is the difference between null and undefined?

A

null type is an object that is explicitly assigned to a variable.

undefined type is undefined where the variable has been declared but has no assigned value

18
Q

What is AJAX?

A

stands for Asynchronous JavaScript and XML. We can send data to the server and get data without refreshing the page.

19
Q

Explain the difference between synchronous and asynchronous.

A

Synchronous is blocking operation while asynchronous is not. Synchronous complete the current code before the next code is executed while asynchronous continue on the next code without completing the current code

20
Q

What are the differences between var, let, and const

A

var is scoped to a function. let and const are block-scoped. Accessible to nearest curly braces (function, if-else, for-loop)

21
Q

What is the DOM?

A

it stands for Document Object Model. This can be used to access and change the document structure, style, and content.

22
Q

What is the difference between a property and a method on a class? / Pluralsight

A

A property is an association between a name and a value; a method is when a function is the value of a property.

23
Q

What is a major reason for adding flow control logic using the return value from an iterator’s next()? / Pluralsight

A

To decide whether or not to return {done: true} instead of {done: false}

24
Q

Given a complex object, foo, with keys that are not known ahead of time, how can you check if a given key, “k”, is in the object without iterating through the whole object? / Pluralsight

A

“k” in foo

25
Q

How can you recreate the following string with a line break into a template literal? console.log(‘string text line 1\n’ + ‘string text line 2’); / Pluralsight

A

console.log(`string text line 1

string text line 2`);

26
Q

What is the output of iterating over the following Set? / Pluralsight

let set = new Set("food");
for (let item of set) console.log(item);
A

f
o
d

27
Q

A web app has a performance-impacting function, impactFoo(), that is called around the same time that a series of async, await AJAX function calls reach completion. How can the function be deferred to be called after any pending event handlers to avoid blocking the application? / Pluralsight

A

setTimeout(impactFoo, 0);