OMM Flashcards
What are some features of javascript
- Functional programming -> Immutablility, like evaluation of functions
- Dynamic typing (No static types)
- First-class functions -> Function is a like variable (e.g. callbacks)
- Huge ecosystem
How can you debug java script applications
- Browser console
- Page inspector
What is the difference in defining functions with keyword and with arrow functions
- () => {} - Can’t be bind to names - Anonymous
- function bla(): Bind to a name
When are fat arrow function used
E.g. callbacks
How does object destructuring works?
- let {foo, bar, baz}= obj; -> same like var foo = obj.foo
- Spread operator … copies other keys of the object into new object with name: let{foo, …rest} = obj; rest.bar == obj.bar;
What are standard prototype array functions?
- Map: Change every element
- Reduce: Aggregate, Accumulate
- Foreach: Iterate
- Filter: Filter
- Find: Returns object -> Array
- FindFirst: Just first ones -> First
Shorten the following code: var array = new array(3)
let arr = [2,3,4];
Shorten following code: if foo: return bar; else: return null
return foo ? bar : null
What is a promise?
- Wrapper for async code
- Promise that a response arrives at some time
- If completes: Resolved / fulfilled
- If fails: Rejected
- Can be chained with .then or .catch
What are the keywords async & await?
- Making functions async wraps the function into a promise
- Await waits for a promise and pauses it at the position till the promise resolves
Describe the difference between let and var and const
- Let is mutable and can be reassigned
- Var is old method for every variable
- Const value is mutable but not the assignment
What is the result of
[ 1, 2, 3, 4 ].map((a) => a * a).reduce((a, b) => a + b)
- [1, 4, 9, 16].reduce((a, b) => a + b)
- 30
Why will this fail: function () { const value = await fetch('http://httpbin.org/get'); .then((res) => res.json()); return value; }
no async on function delcaration
What are main components of a HTTP request?
- request line: get / put
- header: content-type, accept-type
- body: body
- response: status, header, body
What are some common http codes
- 1xx Informational
- 2xx Success
- 3xx Redirect
- 4xx Client error
- 5xx Server error
What are common http methods
- GET
- POST
- PUT
- DELETE
For what stands AJAX?
Asynchronous JavaScript and XML
What are the advantages of using JSON?
- No fixed schema
- Human readable
- Easily convertible to JS
- More dynamic
What are the advantages of using XML?
- Fixed schema
- Namespace
What is the XMLHTTPRequest?
- API to transfer data between client, server
- Not used anymore
What does fetch in JS?
- Simplifying ajax requests
- Use promises for resolving
What are differences between XHR and fetch
- XHR
- Event-callback based
- Create object
- Open URL
- Attach readystatechange
- Send
- Fetch
- Promise based
- Inside javascript function
How are Web APIs often secured?
- Rate limits - requests per user
- Scope of each user
- Access token
What is the difference between authorization vs authentication
- Authentication: Who am I?
- Authorization: What am I allowed to do?
What are different ways to ensure authentication?
- Basic authentication: Username + Password
- pro: quick and easy
- con: Security issue
- Personal access token
- Pro: Security improvement
- OAuth Token
- Pro: Security (lifespan, exchanged regularly)
- Con: More complicated to implement
What is Same Origin Policy?
- Tried to hamper cross site scripting
- Blocks ajax requests from other origins as defined in allowed origins
What does asynchronous actually mean?
That it doesn’t block the whole program
What is the difference between get and post?
- Post alters something, e.g. create user
- Get just gets information, e.g. get user list
How do you avoid SOP(Same Origin Policy) issues?
- Define cross origins
- JSON with padding
- Reverse proxies
Why do we need an eventloop?
- Because javascript is single threaded
- But somehow we need to execute code “at the same time”
- E.g. callbacks, promises, etc.
What are the different event loops?
- Main loop: Executes sequential code
- Message loop: Waites for enqueued messages
- Rendering: Calculates stylesheet, results layout, paints webpage
What types are in javascript?
- undefined
- number
- string
- boolean
- Object
- symbol
- any
How can we check types?
- Typeof
- Instanceof
What is typescript?
- Superset of javascript
- JS with type annotations
Benefits of Typescript
- More concise / accurate code
- More developer control
- Static checking
Why does it make sense to keep JS single threaded?
- Because browser is single threaded as well
- Don’t consume too much resources of user
How does JS convert from int to float?
Point after the number
Explain the difference between imperative and declarative?
- Imperative: Specify how to do something
- Declarative: Specify what should be done
Explain the MVC model
- Model: Data structure / model
- View: Everything user sees
- Controller: How things work / Behaviour
What is the goal of web components?
Having re-usable code
What are the main concepts of web components?
- Custom Elements
- HTML Import
- Templates
- Shadow DOM
What are advantages of web components?
- More declarative
- More readable
- Separation of concerns
- Re-Usable
- Encapsulation
What is a polyfill?
Polyfill is a script which implements a workaround for things which are not implemented