




























































































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
Focused on the AMP (Accelerated Mobile Pages) open-source ecosystem, this exam measures knowledge of AMP component architecture, performance optimization rules, AMP caching, validation, lifecycle hooks, rendering behavior, and restrictions that safeguard page consistency. Candidates must debug AMP markup, propose accessibility improvements, interpret validator errors, and evaluate AMP’s SEO and performance characteristics across mobile-first design.
Typology: Exams
1 / 120
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. What does the Buffer.allocUnsafe(size) method do in Node.js? A) Allocates a zero‑filled buffer of the given size. B) Allocates a buffer without initializing memory, which may contain old data. C) Allocates a buffer and fills it with the value 0xFF. D) Throws an error if the requested size exceeds the maximum allowed. Answer: B Explanation: Buffer.allocUnsafe creates a buffer of the specified size without zero‑filling it, so the memory may contain remnants of previous data, offering better performance but requiring careful handling.
Question 2. Which encoding is used to represent binary data as a printable string consisting of characters 0–9 and A–F? A) utf B) base C) hex D) ascii Answer: C Explanation: The “hex” encoding converts each byte to a two‑character hexadecimal representation, using characters 0‑9 and A‑F.
Question 3. When reading a large file that cannot fit into memory, which Node.js API is most appropriate? A) fs.readFileSync
B) fs.readFile C) fs.createReadStream D) Buffer.from Answer: C Explanation: fs.createReadStream returns a readable stream that emits data chunks, allowing incremental processing without loading the entire file into memory.
Question 4. In a Transform stream, which method must be implemented to modify incoming data? A) _read() B) _write() C) _transform(chunk, encoding, callback) D) _final(callback) Answer: C Explanation: The _transform method receives each chunk, allows transformation, and calls the callback with the transformed data.
Question 5. What is the purpose of the pipeline utility introduced in Node.js 10? A) To automatically convert callbacks into promises. B) To simplify error handling when piping multiple streams together. C) To serialize objects to JSON before writing to a file. D) To spawn child processes with built‑in retry logic. Answer: B
Question 8. **What does the following code output?
function foo(cb) { setTimeout(() => cb(null, 42), 0); } foo((err, result) => console.log(result)); ```** A) Undefined B) 42 C) A promise object D) Nothing, because setTimeout is asynchronous Answer: B Explanation: The callback is invoked after the timeout, printing the value 42. --- Question 9. **Which of the following will correctly create a promise that resolves after 1 second?** A) `new Promise(resolve => setTimeout(resolve, 1000));` B) `Promise.resolve(setTimeout(1000));` C) `new Promise((reject, resolve) => setTimeout(resolve, 1000));` D) `Promise.delay(1000);` Answer: A Explanation: The executor receives resolve first; calling resolve after setTimeout triggers fulfillment after 1 second. --- Question 10. **What is the result of using Promise.all on an empty array?** A) It returns a promise that never resolves. B) It returns a promise that resolves immediately with an empty array. C) It throws a TypeError. D) It returns undefined. Answer: B Explanation: Promise.all resolves instantly with an empty array when given no input promises. --- Question 11. **Which method allows you to wait for the first promise to settle (either fulfill or reject) among several promises?** A) Promise.race B) Promise.any C) Promise.allSettled D) Promise.first Answer: A Explanation: Promise.race resolves or rejects as soon as the first supplied promise settles. --- Question 12. **Consider the following code: ```js async function f() { return 5; } f().then(v => console.log(v)); What is logged?**
Answer: A Explanation: exec returns a ChildProcess with stdout and stderr streams for the child’s output.
Question 15. What is the primary difference between spawn and exec in Node.js? A) spawn buffers the entire output, exec streams it. B) spawn returns a promise, exec uses callbacks. C) spawn provides streaming I/O, exec buffers the entire output into a string. D) spawn can only run shell commands, exec runs binaries directly. Answer: C Explanation: spawn gives you streams for stdin/stdout/stderr, while exec buffers the complete output and passes it to a callback.
Question 16. Which option enables a child process created with fork() to communicate via an IPC channel? A) { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] } B) { env: { IPC: true } } C) { detached: true } D) { shell: true } Answer: A Explanation: Adding ‘ipc’ to the stdio array creates an IPC channel for message passing between parent and forked child.
Question 17. In an IPC message between a parent and a forked child, which method sends a message from the child to the parent? A) process.send() B) child.send() C) parentPort.postMessage() D) ipc.emit() Answer: A Explanation: Inside a forked child, process.send() transmits a serializable object to the parent process.
Question 18. What does EventEmitter.emit('event') return? A) The number of listeners that were invoked. B) A boolean indicating whether the event had listeners. C) The event object itself. D) Nothing (undefined). Answer: B Explanation: emit returns true if the event had at least one listener, otherwise false.
Question 19. Which method registers a listener that will be invoked only the first time the event occurs? A) on() B) addListener()
Explanation: The synchronous version blocks the Node.js event loop while reading, which can degrade performance.
Question 22. What does the flag 'a' mean when passed as the second argument to fs.createWriteStream? A) Append mode – data is added to the end of the file. B) Asynchronous mode – writes are non‑blocking. C) Atomic mode – writes are performed atomically. D) Auto‑close – the stream closes after each write. Answer: A Explanation: The 'a' flag opens the file for appending, preserving existing content.
Question 23. Which method from the fs.promises API reads the contents of a directory and returns an array of file names? A) fs.promises.readdirSync() B) fs.promises.readDir() C) fs.promises.readdir() D) fs.promises.list() Answer: C Explanation: fs.promises.readdir() resolves with an array of directory entries.
Question 24. When using fs.watch, which event name indicates that a file has been removed? A) 'rename' B) 'delete' C) 'remove' D) 'change' Answer: A Explanation: The 'rename' event is emitted for both renames and deletions; the listener must inspect the file’s existence to differentiate.
Question 25. Which of the following properties is NOT part of the fs.Stats object? A) size B) mode C) uid D) path Answer: D Explanation: Stats provides size, mode, uid, gid, atime, mtime, ctime, and birthtime, but not the original path.
Question 26. What is the default behavior of unhandled promise rejections in recent Node.js versions (>=15)? A) They are silently ignored. B) They cause the process to exit with code 1.
Question 29. What does the term “closure” refer to in JavaScript? A) The ability of a function to access variables from its lexical scope even after that outer function has returned. B) The process of garbage collecting unused objects. C) The use of the finally block in try/catch. D) The automatic conversion of objects to JSON. Answer: A Explanation: Closures capture the surrounding lexical environment, allowing inner functions to reference outer variables later.
Question 30. Which ES6 feature allows you to extract properties from an object into distinct variables? A) Spread operator B) Destructuring assignment C) Rest parameters D) Proxy object Answer: B Explanation: Object destructuring lets you pull out properties into separate variables with a concise syntax.
Question 31. What is the effect of placing "use strict"; at the top of a Node.js module? A) Enables ECMAScript modules automatically. B) Disables the EventEmitter system. C) Enforces stricter parsing and error handling, e.g., forbidding undeclared variables. D) Turns off all asynchronous I/O. Answer: C Explanation: Strict mode eliminates some silent errors, disallows certain syntax, and makes the code more secure.
Question 32. In CommonJS, what does module.exports = function(){} achieve? A) It adds a new property named “function” to the exports object. B) It replaces the entire exports object with the provided function. C) It creates a circular dependency warning. D) It has no effect; you must use exports instead. Answer: B Explanation: Assigning directly to module.exports replaces the default empty object with the exported value.
Question 33. Which statement about ES Modules (ESM) in Node.js is correct? A) They are enabled automatically in files with a .js extension. B) The import syntax works only when the file’s package.json has "type": "module". C) require() can be used inside an ES module without any flag. D) ES modules do not support named exports.
Question 36. Which signal does Node.js emit when you press Ctrl+C in the terminal? A) SIGTERM B: SIGKILL C) SIGINT D) SIGHUP Answer: C Explanation: Ctrl+C generates the SIGINT interrupt signal, which Node can listen for via process.on('SIGINT', …).
Question 37. What information does os.cpus() return? A) An array of objects describing each logical CPU core, including model and speed. B) The total number of CPU cores as a single integer. C) The current CPU usage percentage. D) A string with the operating system’s name. Answer: A Explanation: os.cpus() provides detailed info for each logical processor.
Question 38. How can you retrieve the value of an environment variable named DB_HOST in a Node.js script? A) process.env('DB_HOST') B) process.env.DB_HOST
C) env.DB_HOST D) process.getEnv('DB_HOST') Answer: B Explanation: process.env is an object where each property corresponds to an environment variable.
Question 39. In package.json, what is the purpose of the “engines” field? A) To specify the Node.js version(s) required for the package to run. B) To list external command‑line tools the package depends on. C) To define custom npm scripts. D) To set the ECMAScript version to compile to. Answer: A Explanation: “engines” declares compatible Node (or npm) versions, helping consumers know runtime requirements.
Question 40. What does the caret (^) symbol mean in a dependency version like "lodash": "^4.17.20"? A) Accept any version greater than 4.17.20, including major version changes. B) Accept only patch‑level updates (e.g., 4.17.x). C) Accept any version that does not change the left‑most non‑zero digit (i.e., any 4.x.x). D) Pin the version exactly to 4.17.20. Answer: C
A) test B) assert C) verify D) expect Answer: B Explanation: The assert module offers simple assertion functions for testing.
Question 44. When testing an asynchronous function that returns a promise, which Mocha hook should you use to ensure the test waits for the promise to settle? A) it('test', function(done) { … }) with a callback. B) it('test', async function() { await fn(); }) C) it('test', function() { fn().then(done); }) D) All of the above are valid. Answer: D Explanation: Mocha supports callbacks, async/await, and returning the promise directly; all three patterns wait for completion.
Question 45. Which of the following is NOT a valid way to import a CommonJS module in an ES module file? A) import fs from 'fs'; B) import * as fs from 'fs'; C) import { readFile } from 'fs'; D) import fs = require('fs');
Answer: D Explanation: The import = require syntax is TypeScript‑specific and not valid in native ES modules.
Question 46. What does the --experimental-modules flag do in older Node.js versions? A) Enables the use of ES module syntax (import/export). B) Allows loading of native addons written in C++. C) Turns on the V8 inspector. D) Disables the EventEmitter warning. Answer: A Explanation: Before stable ESM support, the flag enabled experimental module loading.
Question 47. Which method of the fs module can be used to atomically replace a file’s contents? A) fs.renameSync B) fs.writeFileSync with the flag 'wx' C) fs.copyFileSync D) fs.truncateSync Answer: B Explanation: The 'wx' flag fails if the file exists; combined with a temporary file and rename, it achieves atomic replacement, but the most direct atomic write is using fs.writeFile with 'wx' to ensure exclusive creation.