Javascript Flashcards

1
Q

What is a Singleton?

A

A class defined so that it can only have one instance, and has a global point of access.

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

What is then difference between adding an async or defer attribute to a script tag?

A

Async: HTML parsing happens concurrently with script fetching. When a script is finished fetching, HTML parsing pauses until that script finishes executing.

Defer: HTML parsing happens concurrently with script fetching. The script waits until HTML has been completely parsed until executing.

(i.e., async blocks parsing while defer does not)

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

There are only six things in Javascript that are not objects (i.e., primitive types). What are they?

A
  1. null
  2. undefined
  3. strings
  4. numbers
  5. booleans
  6. symbols
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain Javascript’s prototype chain.

A

Objects in Javascript can have a parent prototype. When accessing a value in a particular object, Javascript will first see if it is present in that object.

If it is not, it will then look to see if it is present in that object’s prototype. If it is not present in that parent, it will look at that parent’s parent.

This process will continue until either (a) the value is found in an object along the chain or (b) it reaches the end of the chain and no additional prototype is present.

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

What is the difference between the keys iterated through when using a for...in loops and those generated by Object.keys( )?

A

for...in consults enumerable properties in the prototype chain, while Object.keys( ) does not.

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

What is a pure function?

A

A function that (a) give the same input will always produce the same output and (b) does not have any side effects.

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

Create a copy of an array using the spread operator.

A

const copy = […arr]

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

Merge two arrays using the spread operator.

A

const arr3 = […arr1, …arr2]

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

In Javascript, an object is iterable if it has what as a property?

A

Symbol.iterator

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

What promise method is triggered once a promise has either been resolved or rejected?

A

Promise.prototype.finally( )

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

What does it mean to use the npx command instead of npm?

A

You are able run local commands referencing node modules without installing them locally.

So running npx create-react-app hello-world-app would allow you do so successfully without installing create-react-app locally.

You can also use it to run commands under a different node version of run code snippets directly from a URL.

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

What can you do with currying?

A

You can convert multi-argument functions into multiple single argument - or “unary” - functions. Each function returns another function until it provides the desired value at the end of the function chain.

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