


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A series of questions and answers related to node.js, covering topics such as asynchronous programming, callback functions, the v8 engine, and the differences between javascript, node.js, and ecmascript. It also includes code snippets and explanations of key concepts, making it a useful resource for students learning node.js. Structured as a midterm exam, providing a comprehensive review of essential node.js topics. It explores the use of process.argv, the importance of asynchronous and non-blocking code, and the differences between synchronous and asynchronous operations. Additionally, it covers the node repl and file system operations, offering a thorough overview of node.js development.
Typology: Exams
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Any code I write which executes in the browser will work in Node.js, but not vice-versa. - ANSWER-False Based on the code below, which of the following will trigger the if(err) to be true: a) solveRect(12, 2) b) solveRect(40, 12) c) solveRect(12, -2) d) None of the above - ANSWER-c) solveRect(12, -2) Choose the incorrect statement below: a) Callback functions can allow you to defer the execution of a particular function to a later point in time b) If a function takes a callback parameter, it is an asynchronous function c) Callback functions can be created using an anonymous function which is directly passed into another function d) Callback functions can be created using function declarations whose reference is passed into another function. - ANSWER-b) If a function takes a callback parameter, it is an asynchronous function Every callback function is also asynchronous - ANSWER-False Every program needs a runtime environment in order to actually execute - ANSWER- True Explain how process.argv can be used in Node. - ANSWER-process.argv can be used when a user inputs a command line with more arguments. For example, "node app.js extra_argument1 extra_argument2". The property will store all the command line arguments passed when you issue the command to start the node process. The arguments are stored as an array inside the property. For almost every async function built into Node.js, the convention is for the first parameter passed to any callback you give to be an err parameter to check for any errors. - ANSWER-True function addTwo(num) { return num + 2 }; - ANSWER-function declaration function func2(num) { return num > 2 } let numberArr = [1, 2, 3, 4]; let greaterThanTwo = numberArr.filter(func2);
Choose the correct statement: a) The higher order function is filter and the callback function is func b) The callback function is filter and the higher order function is func c) The higher order function is greaterThanTwo and the callback function is func d) The higher order function is filter and there is no callback function. - ANSWER-a) The higher order function is filter and the callback function is func Interpreters perform real-time translation line-by-line of our program, whereas a compiler goes through our entire program from top to bottom before allowing the CPU to execute the code. - ANSWER-True let addTwo = (num) => { return num + 2 }; - ANSWER-arrow, long way let addTwo = function (num) { return num + 2 }; - ANSWER-function expression let addTwo = num => num + 2; - ANSWER-arrow, short way Question 7) Creating a variable and not assigning anything to it in javascript will: a) Cause the javascript interpreter to assign it the value undefined b) Cause the javascript interpreter to assign it the value null c) Cause the javascript interpreter to temporarily ignore it d) Cause the javascript interpreter to give it an integer value of 0 - ANSWER-a) Cause the javascript interpreter to assign it the value undefined Question 8) Choose the one incorrect option in the list: a) it is okay for variables in javascript to contain spaces b) is it okay for variables in javascript to contain both upper and lower case letters c) javascript variable names are case-sensitive d) javascript follows the camelCase standard for naming variables - ANSWER-it is okay for variables in javascript to contain spaces Question 9) Choose the one incorrect option in the list: a) The typeof operator can be written with: typeof 4 b) The typeof operator can be written with: typeof(4) c) The typeof operator can be written with: (typeof(4)) d) The typeof operator can be written with: typeof(((4))) e) The typeof operator can be written with: typeof4 - ANSWER-e) The typeof operator can be written with: typeof Select the incorrect fact:
lose customers due to waiting times. By using asynchronous, the users will be able to do others things while waiting. What is a callback function? Are all callback functions asynchronous? If not, provide an example of a function which has a callback but is not asynchronous: - ANSWER-What is a callback function? Are all callback functions asynchronous? If not, provide an example of a function which has a callback but is not asynchronous: What is the difference between Javascript, Node.js, and Ecmascript? - ANSWER- Javascript is used for front-end development (client-side), it runs in any browser Javascript engine. It works only in specific run time environments. Node.js is used for server-side development, it is an interpreter or running environment for JS. It can be run outside of browsers. Ecmascript is a programming language that forms a basis for JS, it was made to standardize web pages across the board. What is the difference between using the Node REPL vs executing things with the node <filename.js> command? - ANSWER-Node REPL (read eval print loop) is a command line tool used to quickly execute node.js statements. It takes the user's input, interprets it evaluates it, and then display it to the user in the shell. It repeats this process until the user exits the shell. In the same shell, node.js files can be executed using the node <filename.js> command as well. This command goes into the directory where the file is stored and executes the full program. This method is better for larger projects where files might talk to eachother. When I have an asynchronous function like fs.readFile which depends on the result of an fs.writeFile operation first being completed, I should nest the fs.readFile operation inside the callback of fs.writeFile. - ANSWER-True Which function below can be used to read a file asynchronously in Node.js fs.readDir fs.readFileSync fs.writeFile fs.readFile - ANSWER-fs.readFile Which of the following is required in order to write and execute a program? A) A (general purpose) programming language B) A run-time environment C) A Windows PC D) Both A and B - ANSWER-D) Both A and B