web development concepts Flashcards
What are the examples of HTTP Methods???
The different Verb for HTTP Protocol. Examples are GET, POST, PUT DELETE
What does res.json do?
The res.json() function sends a JSON response. This method sends a response (with the correct content-type) that is the parameter converted to a JSON string using the JSON.stringify() method.
Syntax:
res.json( [body] )
Parameters: The body parameter is the body which is to be sent in the response.
Return Value: It returns an Object.
Installation of express module:
Difference of res.json, res.send
res.JSON() is identical to res.send() when an object or array is passed, but it also converts non-objects to json.
HTTP response status code?What are the five types?
Informational responses (100–199) Successful responses (200–299) Redirection messages (300–399) Client error responses (400–499) Server error responses (500–599)
read this for more
What is HTTP Body Data?
HTTP Body Data is the data bytes transmitted in an HTTP transaction message immediately following the headers if there is any (in the case of HTTP/0.9 no headers are transmitted).
Most HTTP requests are GET requests without bodies. However, simulating requests with bodies is important to properly stress the proxy code and to test various hooks working with such requests. Most HTTP requests with bodies use POST or PUT request method.
What is the definition of protocol according to MDN
Protocol
A protocol is a system of rules that define how data is exchanged within or between computers.
Communications between devices require that the devices agree on the format of the data that is being exchanged. The set of rules that defines a format is called a protocol.
In non-programming context, it means below
the system of rules and acceptable behaviour used at official ceremonies and occasions 禮儀,禮節 a breach of Royal protocol 對皇家禮儀的違反 diplomatic protocol 外交禮儀
What is the definition of HTTP
HTTP is a protocol for fetching resources such as HTML documents. It is the foundation of any data exchange on the Web and it is a client-server protocol, which means requests are initiated by the recipient, usually the Web browser. A complete document is reconstructed from the different sub-documents fetched, for instance, text, layout description, images, videos, scripts, and more.
What is the definition of interface?
Interfaces help developers to specify the behaviours of a type without actually specifying the internal implementations. Here is one example of an interface:
interface FlyingAnimal {
fly( height: number):void;
}
Let’s say you have an interface called FlyingAnimal which is used to describe any animals that fly. It has a method called fly(height:number) to specify how high this animal should fly upon calling. It is a common practice to specify only the methods but not the properties to make the interface as flexible as possible.
What is the use of JSON.stringify()
The JSON.stringify() method converts a JavaScript object or value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.
(See examples on MDN if forget)
What does “new” do in Javascript do? Examples?
New keyword in JavaScript is used to create an instance of an object that has a constructor function. On calling the constructor function with ‘new’ operator, the following actions are taken:
A new empty object is created.
The new object’s internal ‘Prototype’ property (__proto__) is set the same as the prototype of the constructing function.
The ‘this’ variable is made to point to the newly created object. It binds the property which is declared with ‘this’ keyword to the new object.
A newly created object is returned when the constructor function returns a non-primitive value (custom JavaScript object). If the constructor function returns a primitive value, it will be ignored. At the end of the function, ‘this’ is returned if there is no return statement in the function body.
function Fruit(color, taste, seeds) { this.color = color; this.taste = taste; this.seeds = seeds; }
// Create an object const fruit1 = new Fruit('Yellow', 'Sweet', 1);
// Display the result document.write(fruit1.color);
What does JSON.parse do?
The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.
What does parse mean in computer science?
In computer science, parsing is the process of analysing text to determine if it belongs to a specific language or not (i.e. is syntactically valid for that language’s grammar). It is an informal name for the syntactic analysis process.
For example, suppose the language a^n b^n (which means same number of characters A followed by the same number of characters B). A parser for that language would accept AABB input and reject the AAAB input. That is what a parser does.
In addition, during this process a data structure could be created for further processing. In my previous example, it could, for instance, to store the AA and BB in two separate stacks.
Anything that happens after it, like giving meaning to AA or BB, or transform it in something else, is not parsing. Giving meaning to parts of an input sequence of tokens is called semantic analysis.
in reading JSON, require(“.file.json) VS fs.readFile,
what is the difference?
require(“./file.json) caches result, which mean it will be store in the program who call it and won’t change even when the retrieved json file is changed. (it will autoly parse the json. Downside, this is sync, it will block other code until it is loaded. But it is good at configuation because you want other data to run after that. Also, it loads faster because it is cache.
fs.readFile, read current state of file, must parse data
is readFileSync sync or async?
it is async!! Check it out in VScode
if a function returns a value, and you add a console.log , will it display in the console
NO, if you console.log the function, it will only display the returned value.