01. A developer copies a default settings object before applying a user's changes:
- const defaults = { theme: 'light', layout: { columns: 2 } };
- const userPrefs = { ...defaults };
- userPrefs.theme = 'dark';
- userPrefs.layout.columns = 3;
- console.log(defaults.theme, defaults.layout.columns);
What is logged to the console?
a) light 3
b) dark 2
c) light 2
d) dark 3
02. A developer needs a function total that accepts any number of numeric arguments, returns their sum, and returns 0 when called with no arguments. The code runs as an ES module.
Which three implementations meet the requirement?
(Choose 3 answers)
a) const total = (amounts) => amounts.reduce((sum, n) => sum + n, 0);
b) const total = function () { return Array.from(arguments).reduce((sum, n) => sum + n, 0); };
c) const total = () => Array.from(arguments).reduce((sum, n) => sum + n, 0);
d) const total = function (...amounts) { return amounts.length ? amounts.reduce((sum, n) => sum + n) : 0; };
e) const total = (...amounts) => amounts.reduce((sum, n) => sum + n, 0);
03. The following code runs in Node.js as a CommonJS script (node app.js):
- Promise.resolve().then(() => console.log('promise'));
- process.nextTick(() => console.log('tick'));
- console.log('sync');
In which order are the messages logged?
a) tick, sync, promise
b) sync, promise, tick
c) sync, tick, promise
d) promise, tick, sync
04. A developer is animating the width of a progress bar. Each update must run once per display refresh, just before the browser paints, and stop running while the tab is in the background.
Which call should schedule each update?
a) setInterval(step, 1000 / 60)
b) requestAnimationFrame(step)
c) requestIdleCallback(step)
d) setTimeout(step, 0)
05. A developer wrote the following unit test with the Node.js assert module:
- const result = parseQuery('team=ops&env=prod');
- assert.strictEqual(result, { team: 'ops', env: 'prod' });
The test fails even though parseQuery returns a new object with exactly those keys and values. assert.strictEqual compares its arguments with Object.is.
Which assertion verifies the contents of the returned object?
a) assert.equal(result, { team: 'ops', env: 'prod' });
b) assert.notStrictEqual(result, { team: 'ops', env: 'prod' });
c) assert.ok(result == { team: 'ops', env: 'prod' });
d) assert.deepStrictEqual(result, { team: 'ops', env: 'prod' });
06. Refer to the code below:
- console.log(null == 0, null >= 0, undefined == null);
What is logged to the console?
a) true true true
b) false false true
c) false true true
d) false true false
07. A developer is debugging a shopping cart and wants to inspect an array of line-item objects in the console as rows and columns, with one column per property.
- const cart = [{ sku: 'A1', qty: 2 }, { sku: 'B7', qty: 5 }];
Which statement displays the data this way?
a) console.table(cart);
b) console.group(cart);
c) console.dir(cart);
d) console.log(cart.join(', '));
08. A developer is building a Node.js HTTP endpoint that sends log archives to clients. Some archives are several gigabytes, and memory use per request must stay small however large the file is. Inside the request handler, res is the response and filePath names the archive.
Which implementation meets the requirement?
a) res.end(fs.readFileSync(filePath));
b) fs.createReadStream(filePath).pipe(res);
c) res.end(await fs.promises.readFile(filePath));
d) fs.readFile(filePath, (err, data) => res.end(data));
09. A login form at Harborview Credit Union submits credentials with fetch. Whatever the outcome, the script then runs window.location.href = '/home';. Testers report that the POST sometimes returns status 500, but when the developer opens the Network panel and submits, the POST entry is gone once /home loads.
Which two steps, used together, let the developer read the failed POST's status code and the request payload it sent?
(Choose 2 answers)
a) Enable Preserve log in the Network panel before submitting the form
b) Open Local Storage in the Application panel to read the request payload
c) Select the POST entry and open its Headers and Payload tabs
d) Enable Disable cache in the Network panel before submitting the form
e) Read the payload in the Console, where failed fetch calls print their request body
10. A subscription service calculates a renewal date one month after the start date:
- const renewal = new Date(2024, 0, 31);
- renewal.setMonth(renewal.getMonth() + 1);
- console.log(renewal.getMonth(), renewal.getDate());
What is logged to the console?
a) 1 29
b) 2 2
c) 1 31
d) 2 31