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 }?
The answer is: undefined, because dot notation looks for a key literally spelled key
The answer is: undefined, because dot notation looks for a key literally spelled key
The answer is: undefined, because dot notation looks for a key literally spelled key
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?
The answer is: order.payment is undefined and undefined has no properties, whereas order.customer is an object that simply lacks that key
The answer is: order.payment is undefined and undefined has no properties, whereas order.customer is an object that simply lacks that key
The answer is: order.payment is undefined and undefined has no properties, whereas order.customer is an object that simply lacks that key
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
The answer is: A number, An array of strings, A nested object
The answer is: A number, An array of strings, A nested object
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 ||?
The answer is: || would also replace a legitimate running total of 0, since 0 is falsy
The answer is: || would also replace a legitimate running total of 0, since 0 is falsy
The answer is: || would also replace a legitimate running total of 0, since 0 is falsy
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.
The answer is: True
9.[2p] When is a Map the better choice than a plain object?
When is a Map the better choice than a plain object?
The answer is: When the keys are data rather than field names you wrote yourself
The answer is: When the keys are data rather than field names you wrote yourself
The answer is: When the keys are data rather than field names you wrote yourself