General Flashcards

1
Q

How spread operator works

A

{ …note } creates a new object with copies of all the properties from the note object. When we add properties inside the curly braces after the spread object, e.g. { …note, important: true }, then the value of the important property of the new object will be true

```
const noteToEdit = notes.find(note => note.id == id);
const newNote = { …noteToEdit, important: !noteToEdit.important };
~~~

const t = [1, 2, 3, 4, 5]
const [first, second, ...rest] = t
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How destruction works

object and array

A
const body = {
content:"this is content",
important: true
}

const {content,important}= body; //const should be named same as in destructed object

with array
const t = [1, 2, 3, 4, 5]
const[one,two] = t // one =1, two =2 
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

es6 object initialiser feature

compact way to init object

A

the names of the keys and the assigned variables are the same, we can write the object definition with a more compact syntax:
```
const age = 37
const name = “Yahor”
const person = {age,name}
person.name //Yahor
~~~
also can be done partially
{ token, username: user.username, name: user.name }

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

The HTTP standard talks about two properties related to request types, safety and idempotence.
Describe this two types

A

Safety means that the executing request must not cause any side effects in the server.

All HTTP requests except POST should be idempotent
if a request does not generate side-effects, then the result should be the same regardless of how many times the request is sent.

POST is the only HTTP request type that is neither safe nor idempotent. so all other method will return same result no matter how much times called ( other requests return only status (put returns updated note), but post return new note(

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

Waht is CORS

A

Cross-Origin Resource Sharing
Same-origin policy restricts how a document or script loaded by one origin can interact with a resource from another origin.
By default, the JavaScript code of an application that runs in a browser can only communicate with a server in the same origin (same goes for other resources).

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

Types of tests

A
  1. unit - testign functions and units outcome
  2. testing where multiple components of the system are being tested as a group, is called integration testing. It occurs after unit testing and before
  3. e2e or system testing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to send auth token with server request

A

There are several ways of sending the token from the browser to the server. We will use the Authorization header. The header also tells which authentication scheme is used. This can be necessary if the server offers multiple ways to authenticate.
Identifying the scheme tells the server how the attached credentials should be interpreted.
The Bearer scheme is suitable to our needs.

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

local storage

A

Local Storage is a key-value database in the browser.
window.localStorage.setItem(‘name’, ‘juha tauriainen’)
window.localStorage.getItem(‘name’)
The storage is origin-specific so each web application has its own storage.
To save object to localstorage use JSON.stringify() and when getting it back JSON.parse()

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

REST urls and methods and what they should return (get post etc.. on urls notes/10 and notes)

A

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, returns 201 and new note
notes/10 DELETE removes the identified resource, returns 204
notes/10 PUT replaces the entire identified resource with the request data, returns updated note
notes/10 PATCH replaces a part of the identified resource with the request data

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

what are the map files (blabla.js.map)

A

files helps to debug minified app - you will see clean structure of the project.
can be deleted for prod

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

TDD what it is about

A

tdd is about fast feedback
a bit test a bit code
taking small steps

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

Transpile vs compile

A

transpile- is from source code to source code
compile is from source code to binary file

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

Dependenices vs devDependencies

A

dev dep - for development, tests, transpilator, minificator, json-server etc.

Devdep are not installed transitively - so they wouln’t be installed for the packages which are listen in your project.json

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

Why to use deltaTime in animations, what is it? how to get it?
How to move object in px/sec (speed = 100)

A

Animations should be frame rate independent
The way to make animation frame rate independent is to compute how much time it took between frames and use that to calculate how much to animate this frame.
~~~
let now;
let then = performance.now();

function draw(now){
//let now = performance.now(); //same if now wasn’t passed

const timePassedinSec = (now-then)/1000 //time between frames updates;

x+=speed*timePassedinSec

then = now
requestAnimationFrame(draw)
}
draw()
~~~

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

How to display FPS

Use deltaTime, dont forget calculate lefover %

A
let then = 0
let fps = 0;

const update = (now) => {

  const delta = now - then;
  fps++
  if (delta >= 1000) {
    then = now - (delta % 1000)
    document.getElementById("p1").innerHTML = `${fps}`;
    fps = 0
  }
  window.requestAnimationFrame(update);
};
window.requestAnimationFrame(update);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Why to use webpack

A
  1. Bundling
    Modules are still not fully supported by browsers - htat is why we combine it into 1 files. Also 1 files is more efficient to load
    css also should be bundled
  2. Transpiling
    JSX to js and latest es6 features
  3. polyfiling - adding missing functionality on older browsers (promise, array.dind)
  4. Minifying the code
  5. creating source maps
  6. setup development and production configuration

Also it gives such tools as dev-server - which will watch our sources and re-bundle when changed (note that this re-bundling will only be made in memory, to rebundle really we need to run a command)

  • eject command in react-app will delete webpack configuration
17
Q

Why to use webpack

A
  1. Bundling
    Modules are still not fully supported by browsers - htat is why we combine it into 1 files. Also 1 files is more efficient to load
    css also should be bundled
  2. Transpiling
    JSX to js and latest es6 features
  3. polyfiling - adding missing functionality on older browsers (promise, array.dind)
  4. Minifying the code
  5. creating source maps
  6. setup development and production configuration

Also it gives such tools as dev-server - which will watch our sources and re-bundle when changed (note that this re-bundling will only be made in memory, to rebundle really we need to run a command)

  • eject command in react-app will delete webpack configuration and all black-magic
18
Q

What are the benefits of server rendering

A

Useful for performance and SEO optimisation
Crucial for first render - when you need to load a lot of js and then build page with it

19
Q

What is tsconfig.json

A

The tsconfig.json file is used to define how the TypeScript compiler should interpret the code, how strictly the compiler should work, which files to watch or ignore,

20
Q

How to create own type in TypeScript

2 ways

A

type Operation = ‘multiply’ | ‘add’ | ‘divide’;
or
interface
interface MultiplyValues {
value1: number;
value2: number;
}

21
Q

What is union type in TS

A

type CoursePart = CoursePartOne | CoursePartTwo | CoursePartThree;

If we will make an array of different types
const courseParts = [
{
name: “Fundamentals”,
exerciseCount: 10,
description: “This is an awesome course part”
},
{
name: “Using props to pass data”,
exerciseCount: 7,
groupProjectCount: 3
},
{
name: “Deeper type usage”,
exerciseCount: 14,
description: “Confusing description”,
exerciseSubmissionLink: “https://fake-exercise-submit.made-up-url.dev”
}
];

and then reference one of them
let second:CoursePart = courseParts[1]
TS will understand what type it is

22
Q

What steps usually includes CI/CD

A
  • Lint: to keep our code clean and maintainable
  • Build: put all of our code together into software
  • Test: to ensure we don’t break existing features
  • Package: Put it all together in an easily movable batch
  • Upload/Deploy: Make it available to the world

In fact, the process for ci and cd may literally be the same with only a check at the end to determine if we are on the main branch and need to do a deployment.

23
Q

What are the options to organise CI and there +/-

A

self-hosted - Jenkins
+:
- environment is under your control
- secrets are never exposed
-:
- complicated to setup
- risks of hardware failures

cloud-based solutions - github actions
+:
- no need to host server
- setup is easier
-:
- you don’t have control over hardware (can’t just add more RAM)

Cloud-based options are also usually billed by build time which is something to consider.

24
Q

What are conainers used for

A

Containers isolate the software running inside, it enables the software to run identically almost anywhere. As such, they are the go-to option in any cloud environment or application with more than a handful of users.

Container is created from an image
you can never actually build a container or download one since containers only exist during runtime

25
Q

Relational vs Non-relational
differences, adv and cons

A

Relational
- structured in tables ( has columns and rows)
- data tables are connected to each other (have relations)
adv:
- easy to manage, data is consistent
- security (encip table, hide info)
- easy backup and recovery

Non relational
- schemaless, ( the database has only a very limited awareness of what kind of data is stored in its collections)
types
- key-value
- column-based
- graph db
- document store
adv
- scalability
- flexibility (since the schema does not need to be defined at the database level, application development may be faster in certain cases, and easier, with less effort needed in defining and modifying the schema in any case.)
- cost effective
- readability ( all info in one document, rather then collecting withJOINTS between tables)
cons
- can get hard to manage