Fullstack Open 1 Flashcards

1
Q

How do you prevent a website from caching content such as images and JavaScript while developing?

A

In the developer console go to the network tab and tick the checkbox for “Disable cache”

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

In a response header what unit of measurement is content-length?

A

content length is the size in bytes.

content-length: 89635

The response size is 89635 bytes.

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

Why is content-type an important response header?

A

It tells the browser what to do with the response.

content-type: image/png
// render this as an image

content-type: text/html; charset=utf-8
// render this as HTML

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

What is the DOM?

A

Document Object Model, or DOM, is an Application Programming Interface (API) which enables programmatic modification of the element trees corresponding to web-pages.

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

You send a POST request to the server and it responds with HTTP status code 302. What does this tell the browser to do?

A

Status code 302 is an URL redirect, with which the server asks the browser to do a new HTTP GET request to the address defined in the header’s Location.

Response Headers
Location: /notes

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

How many HTML pages does a SPA (Single-page application) consist of?

A

SPA-style websites don’t fetch all of their pages separately from the server, but instead comprise only one HTML page fetched from the server, the contents of which are manipulated with JavaScript that executes in the browser.

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

What is JSX compiled into?

A

JSX is compiled into JavaScript.

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

Is it possible to write React as “pure JavaScript” without using JSX?

A

Yes, It is possible to write React as “pure JavaScript” without using JSX. Although, nobody with a sound mind would actually do so.

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

A core philosophy of React is composing applications from many what ?

A

A core philosophy of React is composing applications from many specialized reusable components.

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

Does using a React fragment render an element?

A

No it does render an element.

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

What is the official name of the JavaScript standard?

A

The official name of the JavaScript standard is ECMAScript

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

Browsers do not support all of JavaScript’s newest features, what is the solution to this? What is the most popular tool for doing this?

A

Code run in browsers has to be transpiled from a newer version of JavaScript to an older, more compatible version. Today, the most popular way to do the transpiling is by using Babel.

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

How do you open the Node.js console and what can you do in it?

A

Use the command “node”
You can write JavaScript Code inside it.

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

What is a cool way to exit the Node.js console?

A

type .exit

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

In React code, it is preferable to use the array method concat to the push method, why?

A

concat returns a copy of the array with the new value added. concat does not mutate the original array.

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

What is this an example of

const t = [1, 2, 3, 4, 5]
const [first, second, …rest] = t

what will first second and rest contain

A

Destructuring assignment

console.log(first, second) // 1, 2 is printed
console.log(rest) // [3, 4, 5] is printed

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

What is an object literal?

A

An object literal is created by listing the objects properties within braces:

const object1 = {
name: ‘Arto Hellas’,
age: 35,
education: ‘PhD’,
}

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

What can cause this output from a console.log()
“props value is [object Object]” and how would you avoid it?

A

using the concatenation operator
console.log(“props value is “ + props);

To avoid it log multiple arguments to console.log( )
console.log(“props value is “, props);

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

What is a higher order function?

A

Functions that use other functions as arguments or return functions are named higher-order functions.

// uses a function that is passed as an argument
function iUseFunction(func) {
return func();
}

// Returns a function from a function
function iReturnFunction() {
return function() { return 42 };
}

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

What are first order functions?

A

Functions that use only primitives or objects as arguments, and only return primitives or objects are named first-order functions.

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

Can a function be a value and what does that even mean?

A

Yes a function can be a value (the value of a variable). This means you can store a function in a variable and do stuff with it like pass it as an argument to a higher order function.

const hiFunction = function() {
return ‘Hello!’
};

the value of hiFunction is:
function() {
return ‘Hello!’
};

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

What should the function passed to Array.filter return?

A

It should return a value that coerces to true or false.
If true to keep the element, if false don’t.

23
Q

What should the function passed to Array.map return?

A

The new value for each element in the new Array.

24
Q

How can you format an object in a console.log to be easier to read?

A

JSON.stringify(myObject, null, 2)

2 is the amount of spacing.

25
Q

Why does React need the key property for JSX elements in an Array?

A

When React recurses on the children of a DOM node, it compares the current DOM nodes with the New DOM nodes and checks for changes. Providing a key allows React to efficiently tell what has changed. Especially when the order of items has changed.

https://reactjs.org/docs/reconciliation.html#recursing-on-children

26
Q

What forms a stack of frames?

A

Function calls form a stack of frames.

27
Q

What is the Heap?

A

Objects are allocated in a heap which is just a name to denote a large (mostly unstructured) region of memory.

28
Q

What is a Queue in a JavaScript runtime?

A

A JavaScript runtime uses a message queue, which is a list of messages to be processed. Each message has an associated function that gets called to handle the message.

29
Q

What is a Queue in a JavaScript runtime?

A

A JavaScript runtime uses a message queue, which is a list of messages to be processed. Each message has an associated function that gets called to handle the message.

30
Q

The event loop got its name because of how it’s usually implemented, which usually resembles what?

A

while (queue.waitForMessage()) {
queue.processNextMessage();
}

In this example it waits synchronously for queue.waitForMessage() until there is a message.

31
Q

What does the term “Run-to-completion” mean?

A

Each message is processed completely before any other message is processed.

This offers some nice properties when reasoning about your program, including the fact that whenever a function runs, it cannot be preempted and will run entirely before any other code runs (and can modify data the function manipulates).

32
Q

What is a downside to the “Run-to-completion” model?

A

A downside of this model is that if a message takes too long to complete, the web application is unable to process user interactions like click or scroll. The browser mitigates this with the “a script is taking too long to run” dialog. A good practice to follow is to make message processing short and if possible cut down one message into several messages.

33
Q

When are messages added to the message queue in a web browser?

A

In web browsers, messages are added anytime an event occurs and there is an event listener attached to it. So a click on an element with a click event handler will add a message — likewise with any other event.

34
Q

(() => {

console.log(‘this is the start’);

setTimeout(() => {
console.log(‘Callback 1: this is a msg from call back’);
}); // has a default time value of 0

console.log(‘this is just a message’);

setTimeout(() => {
console.log(‘Callback 2: this is a msg from call back’);
}, 0);

console.log(‘this is the end’);

})();

What would the output be for this code?

A

// “this is the start”
// “this is just a message”
// “this is the end”
// “Callback 1: this is a msg from call back”
// “Callback 2: this is a msg from call back”

35
Q

What does the term “never blocking” mean in regards to the event loop model?

A

A very interesting property of the event loop model is that JavaScript, unlike a lot of other languages, never blocks. Handling I/O is typically performed via events and callbacks, so when the application is waiting for an IndexedDB query to return or an XHR request to return, it can still process other things like user input.

Legacy exceptions exist like alert or synchronous XHR, but it is considered good practice to avoid them. Beware: exceptions to the exception do exist (but are usually implementation bugs, rather than anything else).

36
Q

What are I/O operations?

A

In computing, input/output (I/O, or informally io or IO) is the communication between an information processing system, such as a computer, and the outside world, possibly a human or another information processing system.
Inputs are the signals or data received by the system and outputs are the signals or data sent from it. The term can also be used as part of an action; to “perform I/O” is to perform an input or output operation.

37
Q

VM705:1 Uncaught Error: oops!
at myFunc (:1:28)
at myOtherFunc (:1:28)
at < anonymous >:1:1

If you see this in the console what does it mean?

A

It is showing that an error has been thrown and it is showing the callstack.

The error occurred in myFunc.
Which is a function called inside MyOtherFunc
MyOtherFunc was called inside an anonymous function.

38
Q

For the nth time what does npm stand for?

A

Node Package Manager

39
Q

Where should npm commands always be ran?

A

npm-commands should always be run in the project root directory where package.json lives.

40
Q

How would you install a json-server as a dev dependency?

A

npm install json-server –save-dev

41
Q

The documentation on MDN describes promises as what?

A

A Promise is an object representing the eventual completion or failure of an asynchronous operation.

42
Q

How many states can a promise have and what are they?

A

3, pending, fulfilled and rejected.

43
Q

What does this highlight?
const hook = () => {
console.log(‘effect’)
axios
.get(‘http://localhost:3001/notes’)
.then(response => {
console.log(‘promise fulfilled’)
setNotes(response.data)
})
}

useEffect(hook, [])

A

That the function useEffect actually takes two parameters. The first is a function, the effect itself. The second is a dependency array.

44
Q

What is this type of import?
import http from ‘http’

A

An ES6 module import

45
Q

What is this type of import?
const http = require(‘http’)

A

A CommonJS module import.

46
Q

How different are CommonJS modules and ES6 modules?

A

CommonJS modules function almost exactly like ES6 modules.

47
Q

How do you update the dependencies of a project?

A

run the “npm update” command.

48
Q

What is node’s REPL and how do you access it?

A

Read-Eval-Print-Loop (REPL)
By typing the “node” command.

49
Q

What does nodemon do?

A

nodemon will watch the files in the directory in which nodemon was started, and if any files change, nodemon will automatically restart your node application.

50
Q

What does REST stand for and what is its purpose?

A

Representational State Transfer, aka REST, was introduced in 2000 in Roy Fielding’s dissertation. REST is an architectural style meant for building scalable web applications.

51
Q

What is the functionality of the following URL paths and verbs? First answer is given.

URL verb functionality
notes/10 GET fetches a single resource
notes GET
notes POST
notes/10 DELETE
notes/10 PUT
notes/10 PATCH

A

URL verb functionality
notes/10 GET fetches a single resource
notes GET fetches all resources in the collection
notes POST creates a new resource based on the request data
notes/10 DELETE removes the identified resource
notes/10 PUT replaces the entire identified resource with the request data
notes/10 PATCH replaces a part of the identified resource with the request data

52
Q

What is express built upon?

A

node and its built-in web server module
It is imported like this: const http = require(‘http’)

53
Q

How do you see the headers from a request to express?

A

The headers property on the request object.

request.headers