Javascript Flashcards
What is a Singleton?
A class defined so that it can only have one instance, and has a global point of access.
What is then difference between adding an async or defer attribute to a script tag?
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)
There are only six things in Javascript that are not objects (i.e., primitive types). What are they?
- null
- undefined
- strings
- numbers
- booleans
- symbols
Explain Javascript’s prototype chain.
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.
What is the difference between the keys iterated through when using a for...in
loops and those generated by Object.keys( )
?
for...in
consults enumerable properties in the prototype chain, while Object.keys( )
does not.
What is a pure function?
A function that (a) give the same input will always produce the same output and (b) does not have any side effects.
Create a copy of an array using the spread operator.
const copy = […arr]
Merge two arrays using the spread operator.
const arr3 = […arr1, …arr2]
In Javascript, an object is iterable if it has what as a property?
Symbol.iterator
What promise method is triggered once a promise has either been resolved or rejected?
Promise.prototype.finally( )
What does it mean to use the npx
command instead of npm
?
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.
What can you do with currying?
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.