OMM Flashcards
(108 cards)
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?