⪼ Made with 💜 by realpolyglot.dev
Topics: Console, Events, HTTP, Modules, Packages
- 15 multiple choice questions
- 1.5 minutes per question
- Score in the top 30% to earn a badge
- mocha
- chai
- jest
- assert
// File: person.js
exports = "John";
// File: index.js
const person = require('./person.js');
console.log(person);
-
{'john'}
-
Undefined
-
{}
-
John
-
process
-
process.stdout
-
Buffer
-
process.uptime
-
deepStrictEqual
-
ifError
-
doesNotThrow
-
fail
- to provide a quick way for users to create REST APIs
- to insulate Addons from changes in the underlying JavaScript engine
- to execute multi-threaded code in the Node environment
- ...
You have a script.js
file with the single line of code shown here. What will be the output of executing script.js
with the node
command?
console.log(arguments);
-
undefined
-
an empty string
-
ReferenceError: arguments is not defined
- an object representing an array that has five elements
- c-ares
- V8
- events
- libuv
- types
- promisify
- asyncify
- callbackify
-
util.promisify(child_process.exec())
-
new Promise(child_process.exec)
-
util.promisify(child_process.exec)
-
new Promise(child_process.exec())
- Event names must be camelCase strings.
- Any values returned by the listeners for an emitted event are ignored.
- The
emit
method allows an arbitrary set of arguments to be passed to the listener functions. - When an event emitter object emits and event, all of the functions attached to that specific event are called syncronously.
When a request event is recieved in the HTTP module, what is the type of the first argument passed to that event, usually named req
?
-
http.IncomingMessage
-
http.ServerRequest
-
http.ServerResponse
-
http.ClientRequest
- vm
- sandbox
- v8
- buffer
- binding.gyp
- package.gyp
- gyp.json
- .gyprc
- process
- root
- Buffer
- require
How does it affect the performance of a web application when an execution path contains a CPU-heavy operation, such as calculating a long Fibonacci sequence?
- As Node.js is asyncronous, this is handled by a libuv and a threadpool. The performance will not notably degrade.
- As the application code runs asyncronously within a single thread, the execution will block, accepting no more requests until the operation is completed.
- As Node.js is asyncronous, this is handled by a threadpool and the performance will not notably degrade.
- The current thread will block until the execution is completed and the operating system will spawn new threads to handle incoming requests. This can exhaust the number of allowed threads (255) and degrade performance over time.
-
const numInstances = cluster.instances();
-
const numInstances = cluster.instances().length;
-
const numInstances = process.cpus().length;
-
const numInstances = require('os').cpus().length;
-
concat
-
allocUnsafe
-
from
-
alloc