Objects and nested data
1.[2p] const key = "port"; What does config.key give when config is { host: "localhost", port: 8080 }?
const key = "port"; What does config.key give when config is { host: "localhost", port: 8080 }?
2.[3p] Why does order.payment.method throw while order.customer.email merely gives undefined?
Why does order.payment.method throw while order.customer.email merely gives undefined?
3.[2p] What operator makes order.payment.method give undefined instead of throwing? Write the two characters.
What operator makes order.payment.method give undefined instead of throwing? Write the two characters.
4.[3p] Which of these survive a JSON.stringify and JSON.parse round trip unchanged?
Which of these survive a JSON.stringify and JSON.parse round trip unchanged?
Select all that apply
5.[3p] In counts[key] = (counts[key] ?? 0) + amount, why is ?? used rather than ||?
In counts[key] = (counts[key] ?? 0) + amount, why is ?? used rather than ||?
6.[2p] A tree has a root of size 0 with children of size 3 and 0, and the second of those has children of size 5 and 7. What does a recursive totalSize return for the root?
A tree has a root of size 0 with children of size 3 and 0, and the second of those has children of size 5 and 7. What does a recursive totalSize return for the root?
7.[3p] Match each part of a recursive function to what it does.
Match each part of a recursive function to what it does.
Base case
Recursive case
Combining step
Stack overflow
answers directly, with no further call
what happens when the descent never reaches the base case
calls itself on smaller pieces of the same shape
turns the results of those calls into this call's answer
Show the answer
Base case: answers directly, with no further call Recursive case: calls itself on smaller pieces of the same shape Combining step: turns the results of those calls into this call's answer Stack overflow: what happens when the descent never reaches the base case
8.[2p] Object keys are always strings, so counts[1] and counts["1"] reach the same entry.
Object keys are always strings, so counts[1] and counts["1"] reach the same entry.
9.[2p] When is a Map the better choice than a plain object?
When is a Map the better choice than a plain object?