Nightly Review Flashcards
What is Array.prototype.filter for?
-creates a new array with all elements that pass the condition or test you specify
What is Array.prototype.map useful for?
- Allows you to quickly iterate and manipulate values of an array
- for example, double every element in the array
- creates a new array as well
What is the process object in a Node.js program?
- it’s a global that provides information about, and control over the current node.js processes
- it is always available to node.js applications without using require
- global means it is available in any files, without having to declare it
How do you access the process object in a Node.js program?
- you can explicitly access it using require(‘process);
- b/c it is a global, it is always available w/out require
What is the datatype of process.argv in Node.js?
- returns an array of strings
- it contains the command line arguments passed when the node.js process was launched
What is the JavaScript Event Loop?
- it is a “handler”
- it looks at the stack and the task queue, and if the stack is empty it takes the first thing on the queue and pushes it onto the stack
- it allows JavaScript to run tasks concurrently
What is the difference between “blocking” and “non-blocking” with respect to how code is executed?
- blocking code is code that runs within the stack
- non-blocking code is code that is put into the callback queue
What is a JavaScript module?
- a module is a single JS file
- each file in node.js is treated as a separate module
What values are passed into a Node.js module’s local scope?
-exports, require, module, __filename, and __dirname
Give two examples of truly global variables in a Node.js program
-global, process, setTimeOut, setInterval, Buffer
What is the purpose of module.exports in a Node.js module?
-to use functions, objects, or arrays in other modules
How do you import functionality into a Node.js module from another Node.js module?
-require function, and then the path of the file
require(‘./filename’);
What is a directory?
-a file that lists other files
What is a relative file path?
- it’s the path towards your file from wherever you are
- starts with ./ (or can leave it off, the ./ is implied)
What is an absolute file path?
The full path, starting at the root of your system
What module does Node.js include for manipulating the file system?
the file system module
What method is available in the Node.js fs module for writing data to a file?
writeFile method
Are file operations using the fs module synchronous or asynchronous?
both!
writeFile is async,
writeFileSync is sync
What is JSON?
- it is a string
- text based data following javascript object syntax
What is serialization and why is it useful?
- serialization: converting a native object to a string so it can be transmitted across the network
- the process of turning an object in memory into a stream of bytes so you can store it on a disk or send it over a network
- allows you to convert your data into JSON and communicate with servers
What is deserialization and why is it useful?
- deserialization: converting a string to a native object
- the reverse: turning a stream of bytes into an object in memory
How do you serialize data into a JSON string using JavaScript?
JSON.stringify()
How do you deserialize a JSON string using JavaScript?
JSON.parse()
What is a client?
- a computer or software that accesses a service made available by a server
- something that sends a request