JS Flashcards

1
Q

What is event delegation?

A

Event delegation is an event handling pattern that allows events to be handled at higher levels of the DOM tree other than where the event was first received.

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

How does event delegation work?

A

Event delegation works because of event bubbling, which allows events to propagate up through the DOM tree to the root. Because of this, events can be handled on any ancestor element of the element where the event was received.

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

Explain why the following doesn’t work as an IIFE: function foo(){ }();. What needs to be changed to properly make it an IIFE?

A

An IIFE is an anonymous function, thus cannot be named. To make the function an IIFE the name ‘foo’ must be dropped to make it anonymous and the function must be enclosed within a grouping operator. (function () {})()

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

What is an IIFE in JS?

A

An IIFE is an immediately invoked function expression meaning that it is a function that is runs as soon as it is defined.

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

What’s the difference between a variable that is: null, undefined or undeclared? How would you go about checking for any of these states?

A

A variable that is undeclared has not been created yet. A variable that is undefined has been declared, but does not have a value. A variable that is null has been declared and has a value of nothing.

To check is a variable is undeclared, one could console.log the variable. If it does not exist a ReferenceError will be thrown.

To check for undefined or null, one could compare the variable with the primative values of undefined or null using the ‘===’.

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

What is a closure? How/Why would you use one?

A

A closure is the combination of a function bundled together with references to its surrounding state. A closure gives access to an outer function’s scope from an inner function.

Closures are useful because they associate data with a function that operates on that data. You can use closures anywhere that might normally use an object with only a single method.

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

Describe the main difference between a .forEach() loop and a .map() loop. Why you would pick one versus the other?

A

The main difference is that a forEach loop mutates the calling array while a map loop utilizes return values and returns a new Array of the same size.

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

What’s a typical use case for anonymous functions?

A

A typical use case for an anonymous function would be an IIFE, where a function is created and then immediately run.

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

How do you organize your code? (module pattern, classical inheritance?)

A

no answer yet

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

What’s the difference between host objects and native objects?

A

Native objects are standard javascript objects provided by javascript itself. They are also know as built-in objects, pre-defined objects, or global objects. (ex: String(), Number(), true).

Host objects are environment-specific javascript objects, and may vary as per the environment of the machine in which the javascript is being used. Host objects are host specific and may differ from one host to another. (ex: window, NodeList, console).

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

Difference between: function Person(){}, var person = Person(), and var person = new Person()?

A

no answer yet

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

What’s the difference between .call and .apply?

A

The difference is that call() takes arguments separately and apply() takes arguments as an array.

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

Explain Function.prototype.bind().

A

The bind() method creates a new function that, when called, calls this function with its ‘this’ keyword set to the provided value, and a given sequence of arguments preceding any provided when the new function is called.

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

When would you use document.write()?

A

Conventional wisdom would deem using document.write() as bad practice as using it after a page load would replace all the content of the page with whatever is placed as a parameter. A possible ‘approved’ time would be for third party code to add their scripts to a page.

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

What’s the difference between feature detection, feature inference, and using the UA string?

A

Feature detection tries to verify if a feature exists, such as geolocation.

Feature inference infers if A exists that it can be assumed that B exists. Geolocation exists so the user must be using a modern browser.

UA string helps identify which browser is used by the user.

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

What is AJAX?

A

AJAX stands for Asynchronous Javascript and XML and it allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes. This makes it possible to update parts of a web page without reloading the whole page.

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

What are the advantages and disadvantages of using AJAX?

A

The advantages of using AJAX:
1. Can use asynchronous calls to reload parts of a web page without having to reload the whole page.
2. Can reduce server traffic and increase speed by allowing applications to render without data.
3. XMLHttpRequest transfers and manipulates the XML data to and from a web service using HTTP. Its purpos is to establish an independent connection between the webpage’s client-side and server.
4. Can reduce bandwidth usage by fetching particle contents instead of transmitting the entire page’s content; meaning you can bring data from the db and store it into the db to perform background without reloading the page.
5. AJAX method enables precise and immediate form validation.

The disadvantages of using AJAX:
1. Open-source making it less secure than other technologies.
2. Search engines cannot index AJAX pages.
3. AJAX can cause difficulties for web pages to debug as well as make them prone to security issues in the future.
4. AJAX has a dependency on JS, so only browsers that support JS or XMLHttpRequest can use AJAX techniques.
5. Bookmarking a specific state can be challenging due to the dynamic web page.
6. If clicking the browser back button, the page may not return to the previous state because successive AJAX requests are unable to register with the browser’s history.

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

What is hoisting?

A

not answered yet

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

Describe event bubbling.

A

Event bubbling happens when an element receives an event, and that event propagates to its parent and ancestor elements in the DOM tree until it gets to the root element. This is default behavior and can be prevented by using the ‘stopPropagation’ method of the event object.

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

What’s the difference between an “attribute” and a “property”?

A

Attributes:
1. Defined by the HTML and are used to customize a tag.
2. Value is constant.
3. Used to initialize the DOM properties.

Properties:
1. Defined by the DOM
2. Value is variable
3. No job is defined

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

Why is extending built-in JS objects not a good idea?

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

How do you extend built-in objects in JS?

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

What is the difference between the document load event and document DOMContentLoaded event?

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

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

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

Explain the same-origin policy with regards to JS.

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

Make this work: duplicate([1,2,3,4,5]); result: [1,2,3,4,5,1,2,3,4,5]

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

Why is it called a ternary expression? What does the word ternary indicate?

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

What is ‘use strict’? What are the advantages and disadvantages to using it?

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

Create a for loop that iterates up to 100 while outputting ‘fizz’ at multiples of 3, ‘buzz’ at multiples of 5 and ‘fizzbuzz’ at multiples of 3 and 5

A
30
Q

Why is it, in general, a good idea to leave the global scope of a website as-is and never touch it?

A
31
Q

What is global scope?

A
32
Q

Why would you use something like the load event? Does this event have disadvantages? Do you know any alternatives, and why would you use those?

A
33
Q

Explain what a single page app is and how to make one SEO-friendly.

A
34
Q

What is the extent of you experience with Promises and/or their polyfills?

A
35
Q

What are the pros and cons of using Promises instead of callbacks?

A
36
Q

What are some of the advantages/disadvantages of writing JS code in a language that compiles to JS?

A
37
Q

What tools and techniques do you use debugging JS code?

A
38
Q

What language constructions do you use for iterating over object properties and array items?

A
39
Q

Explain the difference between mutable and immutable objects.

A
40
Q

How do you make an object immutable?

A
41
Q

Explain the difference between synchronous and asynchronous functions.

A
42
Q

What is the event loop? What is the difference between call stack and task queue?

A
43
Q

Explain the differences on the usage of foo between function foo() {} and var foo = function() {}.

A
44
Q

What are the differences between variables created using let, var and const?

A
45
Q

What are the differences between ES6 class and ES5 function constructors?

A
46
Q

Can you offer a use case for the arrow function syntax? How does this differ from other functions?

A
47
Q

What advantage is there for using the arrow syntax for a method in a constructor?

A
48
Q

What is the definition of a higher-order function?

A
49
Q

Can you give an example of destructuring an object or an array?

A
50
Q

ES6 template literals offer a lot of flexibility in generating strings, can you give an example?

A
51
Q

Can you give an example of a curry function and why this syntax offers an advantage?

A
52
Q

What are the benefits of using spread syntax and how is it different from rest syntax?

A
53
Q

How can you share code between files?

A
54
Q

Why would you want to create static class members?

A
55
Q

Can you name two programming paradigms important to JS app developers?

A
56
Q

What is functional programming?

A
57
Q

What is the difference between classical inheritance and prototypal inheritance?

A
58
Q

What are the pros and cons of functional programming vs object-oriented programming?

A
59
Q

What are two-way data bindings and one-way data flow and how are they different?

A
60
Q

What is a closure?

A
61
Q

What is a promise?

A
62
Q

What is a callback?

A
63
Q

What is a cookie? What are the differences between cookies, localStorage and sessionStorage?

A
64
Q

What is prototypal inheritance?

A
65
Q

What is the DOM?

A
66
Q

What are some status codes that you know?

A
67
Q

What is a 500 status code?

A
68
Q

What is a 401 status code?

A
69
Q

What are some HTTP code you’re familiar with?

A
70
Q

What is the difference between PUT and PATCH?

A
71
Q

What is a REST api?

A