Quiz: Node.js
Node.js questions from real interviews as a quiz, with an explanation for every option.
Try it: 5 questions
Loading…
Sample questions
What happens if code accesses a
letvariable before its declaration is executed in the current scope?- A
SyntaxErroris thrown before the program starts. - The variable is automatically assigned
null. - A
ReferenceErroris thrown because the variable is in the TDZ. - It returns
undefined, as an access to avarvariable would.
- A
How does Node.js typically perform asynchronous file-system operations such as
fs.readFile?- It submits the operation to the libuv thread pool and runs the JavaScript callback on the main thread.
- It sends the operation to a separate Node.js process that returns the result.
- It performs the operation synchronously on the main thread but postpones the callback.
- It runs both the operation and the callback in a separate JavaScript thread.
When should you typically optimize JavaScript code in a Node.js application?
- After every code change, regardless of its performance impact
- Before implementing the core functionality, to prevent any delays from the start
- After implementing the core functionality, once metrics reveal bottlenecks
- Only after the application has been running in production for a long time
What is the primary function of a
Buttonin a user interface?- Store user data on the server
- Set the position of other elements on the page
- Trigger an action when the user clicks it
- Display static text without interaction
Can a resource identifier be sent in the body of a POST request?
- No, an identifier can only be sent in the URL.
- Yes, but the server must use the supplied ID instead of generating its own.
- No, POST requests can contain only fields without an identifier.
- Yes, if the API contract allows it; the server can accept that ID.
What is the primary role of controllers in Nest.js?
- Accept HTTP requests, route their handling, and return responses to clients.
- Run application business logic independently of HTTP requests.
- Store application data and manage its persistence in a database.
- Configure dependencies and wire application components together.
What happens to the promise returned by
Promise.allif one of its input promises rejects?- It rejects with the same reason and cancels the other promises.
- It waits for the other promises to settle, then rejects with the first error.
- It ignores the error and resolves with the results of fulfilled promises.
- It rejects with the same reason, while the other promises keep running.
What is a thread pool in Node.js?
- A set of reusable worker threads that take tasks from a queue.
- A set of separate Node.js processes started to handle requests.
- A mechanism that starts a new thread for every incoming task.
- An event queue where the Event Loop runs JavaScript code in sequence.
Which statement correctly describes
varin JavaScript?- The variable is function-scoped and may be accessed before its declaration line because of hoisting.
- The variable is block-scoped, but is hoisted only within the block.
- The variable is block-scoped and accessible only inside
{}. - The variable is globally scoped regardless of where it is declared.
What is the main difference between Node.js clustering and launching processes with
child_process?- A cluster starts processes one at a time, while
child_processautomatically distributes incoming connections among them. - A cluster starts server workers and distributes connections among them, while
child_processis for launching separate programs and tasks. - A cluster uses multiple threads within one process, while
child_processcreates processes only for HTTP requests. - A cluster launches separate programs, while
child_processcreates HTTP server copies and distributes connections among them.
- A cluster starts processes one at a time, while