WEB Flashcards
What is a callback function?
A callback function is a sent function to an another function as an argument to be used.
What is ECMA script ? What is the difference between Javascript & ECMA script ?
ECMA Script is a language specification that defines how a script language should work, while Java Script is an popular implementation of it.
JavaScript is a programming language initially created by Netscape, whistl ECMAScript consists of specifications (syntax, semantics, structure) for a scripting language created by European Computer Manufacturers Association (ECMA). JavaScript is one implementation based on ECMAScript standards.
What is the difference between let & var ?
Declaring a variable with let
, it will be accesible only within the block it was declared, while declaring with var
, the variable can be accesed globally.
Write an example where using the var
declaration instead of the let
could create a hard to debug code.
function example() { for (var i = 0; i < 5; i++) { setTimeout(function () { console.log(i); }, 1000); s; } }
In this example the value of i
will be changed before the console will be executed so it will show five times 5.
function printNumbers(){ var num = 10; if (true){ var num = 20; } console.log(num) } printNumbers() // Output: 20
function printNumbers(){ let num = 10; if (true){ let num = 20 } console.log(num); } printNumbers() // Output: 10
Give a practical example where you would use the reduce
function in javascript.
let cart = [ { name: "bananas", price_per_unit: 7.99, quantity: 1.4 }, { name: "bread", price_per_unit: 4.5, quantity: 2 }, { name: "eggs", price_per_unit: 1, quantity: 20 }, ]; let total = cart.reduce((acc, curr) => acc + curr.price_per_unit * curr.quantity, 0);
The total
variable will be the total of a receipt.
Give a practical example where you would use the map
function in javascript.
let cart = [ { name: "bananas", price_per_unit: 6.99, quantity: 1.4 }, { name: "bread", price_per_unit: 3.5, quantity: 2 }, { name: "eggs", price_per_unit: 0.8, quantity: 20 }, ]; cart.map((product) => product.price_per_unit *= 1.2;); console.log(cart[0]);// {name: 'bananas', price_per_unit: 8.388, quantity: 1.4}
In this example all the prices will be increased by 20%.
Give a practical example where you would use the filter
function in javascript.
let cart = [ { name: "bananas", price_per_unit: 6.99, quantity: 1.4 }, { name: "bread", price_per_unit: 3.5, quantity: 2 }, { name: "eggs", price_per_unit: 0.8, quantity: 20 }, ]; let newcart = cart.filter((product) => product.price_per_unit < 5); console.log(newcart.length); // The result will be 2 because bananas price_per_unit is 6.99 > 5
In this example filter
creates a new array
that contains only the products that has the price_per_unit
under 5
.
What is a web server?
A web server is a software that responds to requests from clients or web browsers, and serves web pages to them over the Internet or a local network.
Explain the client-server architecture.
Client-server architecture is a computing model where software applications or systems are divided into two main parts: the client and the server. They iteract with each other using a communication protocol such as HTTP. When a client requests data from a server, the server sends back the requested data. The client can then use this data to provide the user with the required functionality. Same with others methods like :PUT,POST,DELETE etc
What is the difference between synchronous and asynchronous execution?
Synchronous and asynchronous execution refer to two different ways in which a computer program can execute instructions.
- Synchronous execution means that the program executes instructions one at a time, in order, and each instruction must complete before the next one can start.
- Asynchronous execution means that the program does not wait for an instruction to finish before moving on to the next one. Instead, the program executes instructions in a non-blocking manner, allowing multiple instructions to be executed simultaneously
What is npm
? Why is it useful?
npm
means Node Package Manager, and it is the default package manager for Node.js. It is used to install, update, and manage dependencies for Node.js projects. It also alows developers to publish their own packages, it ensures that all the packages are up to date and is easy to use with simple commands in the terminal
What is the difference between the dependencies
& devDependencies
in a package.json
file ?
The main difference between dependencies and devDependencies is that dependencies are required for the project to function correctly, while devDependencies are only needed during development and testing.
What would be the impact of javascript fetch
if it was not asyncronous ?
If fetch was not asynchronous it would blocked the execution of other code, the page would freeze until each request was completed, making the user experience slow and unresponsive.
What benefits would bring to a developer to use the Postman
application ?
- Testing APIs: Postman provide a user-friendly interface for making requests, inspecting responses, and debugging issues.
- Collaboration: Postman allows teams to collaborate on API development by sharing collections, requests, and environments and it provides a workspace where developers can work together on a single API project
- Automating tests: Postman allows developers to create automated tests for APIs and web services using its testing framework
- Mock servers: Postman provides a mock server feature that allows developers to simulate an API endpoint and test the API without actually sending requests to the real server.
- Monitoring APIs: Postman offers an API monitoring feature that allows developers to monitor APIs and web services for performance, uptime, and errors.
List the parts of the URL.
- Protocol:
http://
,https://
,ftp://
etc - Domain/Host (a domain name or IP address)
- Port (ex:3000)
- Path:
/example/of/path
- Query string:
?key1=value1&key2=value2
- Fragment identifier(ID):
#section1
How does an HTTP Request look like? What are the most relevant HTTP header fields?
fetch(url, {method: 'PUT', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer <token' }, body: JSON.stringify(obj)}) .then(response = response.json()) .then(data = console.log(data)) .catch(error = console.error(error));
What is query parameter?
A query parameter is a part of a URL that contains data to be sent to a web server as a part of a request. Query parameters are appended to the end of a URL after a question mark (?), and multiple parameters can be separated by an ampersand (&).
List the parts of the URL.
- Protocol:
http://
,https://
,ftp://
etc - Domain/Host (a domain name or IP address)
- Port (ex:3000)
- Path:
/example/of/path
- Query string:
?key1=value1&key2=value2
- Fragment identifier(ID):
#section1
What kind of HTTP status codes do you know?
- 200 - The request has succeeded and returned the requested data.
- 400 Bad Request - The server was unable to understand the request due to invalid syntax.
- 404 Not Found - The requested resource was not found on the server.
- 405 Method Not Allowed - The requested method is not allowed for the specified resource.
Why should you ignore the node_modules
folder in .gitignore
?
Because this folder contains a large number of files and directories wich can have a big dimension. And they can be easily be instaled with npm install
. Also there could be dublicates, changes and conflicts hard to be managed because of the quantity of the files.
Why is it recommend for a developer to use the http methods get
, put
, delete
?
- These HTTP methods have well-defined and known meanings. For example,
GET
is used for retrieving resources,PUT
is used for updating existing resources, andDELETE
is used for deleting resources. GET
requests can be cached by web browsers and sending the same request multiple times ,likePUT
orDELETE
has the same effect as sending it once
How does a POST
request look like when it is made from a web browser (on the front end written) ?
fetch(url, {method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer <token' }, body: JSON.stringify(obj)}) .then(response = response.json()) .then(data = console.log(data)) .catch(error = console.error(error));
What is an API?
An API is like a messenger that takes requests from one system and sends them to another system, and then delivers the response back to the requesting system.
What is REST API?
REST API is an API that follows the principles of the REST architectural style. REST is a set of constraints and principles for designing web-based software architectures. They allow developers to build systems that can be accessed from a variety of devices and platforms.
What is JSON and how do we use it?
JSON stands for JavaScript Object Notation. It is a data interchange format that is easy for humans to read and write and easy for machines to parse and generate.
In JavaScript we can use the JSON.parse() method to parse a JSON string into a JavaScript object, and the JSON.stringify() method to convert a JavaScript object into a JSON string.
What is API versioning ?
API versioning is the practice of creating multiple versions of an API to manage changes to the API over time. Some changes can have an impact on clients that depend on the API so versioning provides a way to manage these changes while minimizing disruption to clients.
Give 3 examples of HTTP response status codes ? Explain what each number means.
- 200 OK : It indicates that the request was successful
- 404 Not Found: This indicates that the server could not find the requested resource because the URL is incorrect, the resource has been deleted or moved, or the user does not have permission to access the resource.
- 400 Bad Request: It indicates that the server cannot process the client’s request because the request has invalid syntax or is malformed
How does the ternary operator
looks like in javascript?
codintion ? expresion1 : expresion2
How to import a function from another module in JavaScript?
import <functionName> from "<path/to/module's/file>"
What is a shallow copy on an object?
IS a new object that is a copy of the original object but shares the same references to the objects contained within it.
What is a callback function? Tell some examples of its usage.
A callback function is a sent function to an another function as an argument to be used.
- For asynchronus fetch functions:
fetch('/example/data') .then(response = response.json()) .then(data = { console.log(data) });
- Adding events:
button.addEventListener('click', function() { alert("Event trigered) });
What is object destructuring in javascript?
Object destructuring is a method that allows us to extract values from objects and assign them to variables.
What is array destructuring in javascript?
Array destructuring is a method that allows us to extract values from arrays and assign them to variables.
What is the spread operator in js
?
Spread operator allows us to spread the contents of an iterable (such as an array or an object) into individual elements with (...
) notation