JavaScript Objects & Key/Value Manipulation Quiz
Explore 75 JavaScript object questions that cover construction, property access, mutation, introspection, cloning, and immutability. Thirty questions include runnable snippets so you can reason through exact behaviour before answering.
Question 1
What string is printed when the following customer object is logged?
const customer = { name: 'Nia', tier: 'gold' }
console.log(customer.name + ' - ' + customer['tier'])Question 2
What value is printed for report.priority?
const key = 'priority'
const report = { id: 7 }
report[key] = 'high'
console.log(report.priority)Question 3
A meeting object is cloned with spread before mutation. What tuple is logged?
const meeting = { title: 'Kickoff', owner: 'Sam' }
const copy = { ...meeting }
copy.owner = 'Dana'
console.log(meeting.owner, copy.owner)Question 4
After adding and deleting properties, what keys remain on the device object?
const device = { id: 'A1', status: 'online' }
device.location = 'eu-west'
delete device.status
console.log(Object.keys(device))Question 5
Consider a nested configuration. What value is printed?
const config = { feature: { enabled: true, rollout: 0.3 } }
console.log(config.feature.rollout)Question 6
What does the following log statement produce after Request is sealed?
const Request = { method: 'GET', retries: 1 }
Object.seal(Request)
Request.url = '/status'
Request.retries = 2
delete Request.method
console.log(Request)Question 7
Which value is logged when using a computed property?
const suffix = 'Id'
const record = { ['user' + suffix]: 42 }
console.log(record.userId)Question 8
What is the console output when merging objects with spread order sensitivity?
const base = { role: 'member', active: true }
const overrides = { active: false, region: 'us' }
const user = { ...base, ...overrides }
console.log(`${user.role}:${user.active}:${user.region}`)Question 9
After deleting a nonexistent property, what does the log show?
const invoice = { total: 199 }
delete invoice.tax
console.log(invoice.total, 'tax' in invoice)Question 10
How many iterations does the for…in loop perform?
const featureFlag = { id: 'beta', enabled: true, cohort: 'A' }
let count = 0
for (const key in featureFlag) {
if (Object.prototype.hasOwnProperty.call(featureFlag, key)) count++
}
console.log(count)Question 11
What string is produced after Object.entries mapping?
const env = { NODE_ENV: 'prod', REGION: 'us-east-1' }
const pairs = Object.entries(env).map(([key, value]) => `${key}=${value}`)
console.log(pairs.join(';'))Question 12
When freezing an object, what happens to nested objects?
const settings = { theme: { dark: true }, version: 1 }
Object.freeze(settings)
settings.version = 2
settings.theme.dark = false
console.log(settings.version, settings.theme.dark)Question 13
What value is returned by checking key existence with in?
const payload = Object.assign({ id: 1 }, { status: 'queued' })
console.log('status' in payload)Question 14
What output is produced when iterating over Object.values?
const metrics = { open: 3, closed: 5 }
const sum = Object.values(metrics).reduce((acc, value) => acc + value, 0)
console.log(sum)Question 15
A dynamic property is deleted after it is added. What does the log show?
const session = {}
session['user-' + 42] = 'active'
delete session['user-' + 42]
console.log(Object.keys(session).length)Question 16
How does property shadowing behave in the following snippet?
const base = { status: 'pending' }
const draft = Object.create(base)
draft.status = 'ready'
console.log(draft.status, base.status)Question 17
What happens when using Object.assign to merge into the first argument?
const defaults = { retries: 3, timeout: 1000 }
const params = Object.assign({}, defaults, { timeout: 2000 })
console.log(defaults.timeout, params.timeout)Question 18
What does hasOwnProperty report for an inherited property?
const proto = { shared: true }
const obj = Object.create(proto)
console.log(obj.hasOwnProperty('shared'))Question 19
What tuple is printed after cloning a nested object with shallow spread?
const state = { user: { name: 'Lee' }, loaded: false }
const clone = { ...state }
clone.user.name = 'Jo'
console.log(state.user.name, clone.loaded)Question 20
What is logged after sealing and attempting to delete a property?
const policy = { active: true, tier: 'pro' }
Object.seal(policy)
delete policy.tier
console.log('tier' in policy)Question 21
What string is produced when mixing dot and bracket notation with numeric keys?
const logs = { '200': 'ok', 404: 'missing' }
console.log(logs[200] + '/' + logs['404'])Question 22
How many properties are reported by Object.keys after using Object.defineProperty with enumerable false?
const entity = { id: 1 }
Object.defineProperty(entity, 'secret', { value: 99, enumerable: false })
console.log(Object.keys(entity).length)Question 23
What happens when destructuring with default values?
const response = { status: 200 }
const { status, data = null } = response
console.log(status, data)Question 24
What value does hasOwnProperty return after deleting a key defined on the prototype?
function Service() {}
Service.prototype.mode = 'sync'
const instance = new Service()
delete instance.mode
console.log(instance.hasOwnProperty('mode'))Question 25
What is the final value of score after using the in operator to guard updates?
const scorecard = { alice: 10 }
if ('alice' in scorecard) scorecard.alice += 5
if (!('bob' in scorecard)) scorecard.bob = 3
console.log(scorecard.alice + scorecard.bob)Question 26
A product object is updated using Object.assign to merge metadata. What string is logged?
const product = { sku: 'S-1', stock: 10 }
Object.assign(product, { stock: 5, discontinued: false })
console.log(`${product.stock}:${product.discontinued}`)Question 27
Which value is returned when safely reading a nested property with optional chaining?
const profile = { info: { email: '[email protected]' } }
console.log(profile.preferences?.theme ?? 'light')Question 28
What is the effect of using delete on a property from a frozen object?
const attrs = Object.freeze({ kind: 'task', owner: 'Jo' })
const result = delete attrs.owner
console.log(result, attrs.owner)Question 29
How does Object.entries behave when properties are added in a different order?
const summary = {}
summary.user = 'Ada'
summary.total = 5
const entries = Object.entries(summary)
console.log(entries[0][0], entries.length)Question 30
What result is printed when using Object.assign for shallow merging of nested settings?
const baseSettings = { theme: { color: 'blue' }, mode: 'lite' }
const finalSettings = Object.assign({}, baseSettings, { mode: 'dark' })
finalSettings.theme.color = 'green'
console.log(baseSettings.theme.color, finalSettings.mode)Question 31
When using object literals, which statement best describes how duplicate keys are handled?
Question 32
Why is bracket notation required when accessing a property whose name is stored in a variable?
Question 33
Why might deleting properties inside a for…in loop produce unexpected iteration results?
Question 34
How does the in operator differ from hasOwnProperty?
Question 35
Why is Object.keys preferable to for…in when you only care about an object’s own enumerable properties?
Question 36
Why does JSON.stringify ignore functions on objects?
Question 37
When using Object.values on a dictionary, why must you be mindful of numeric strings ordering?
Question 38
Why is Object.assign unsuitable for deep cloning nested objects?
Question 39
Why might Object.freeze be preferred over const when preventing configuration changes?
Question 40
What is the main limitation of using hasOwnProperty directly on objects created with Object.create(null)?
Question 41
Why is using Object.keys(obj).length to check emptiness usually safe for plain objects?
Question 42
When migrating data from arrays to objects, why might you prefer Object.fromEntries?
Question 43
Why is it risky to rely on JSON.parse(JSON.stringify(obj)) for cloning when objects contain Date instances?
Question 44
What advantage does Object.entries provide over Object.keys for transforming objects into arrays of label/value pairs?
Question 45
Why might you prefer using Object.assign({}, source) over spread when targeting legacy environments?
Question 46
Why is it considered best practice to use Object.create(null) for dictionary-like objects that store untrusted keys?
Question 47
Why does using delete on arrays (e.g., delete arr[0]) differ from using splice?
Question 48
When converting objects to Map instances, what key difference should you account for?
Question 49
What is the primary difference between Object.seal and Object.freeze?
Question 50
Why is it beneficial to document whether an API returns plain objects versus instances of custom classes?
Question 51
Why might you wrap property updates in Object.hasOwn (or hasOwnProperty) when merging user-supplied payloads?
Question 52
How can you create a shallow immutable snapshot of an object for logging purposes without affecting future mutations?
Question 53
What benefit does Object.entries combined with array destructuring provide in transformation pipelines?
Question 54
Why should you prefer Object.hasOwn over obj.hasOwnProperty when obj might come from untrusted sources?
Question 55
When should you prefer spread syntax over Object.assign for cloning?
Question 56
Why does using Object.freeze on configuration data improve reliability in multi-team environments?
Question 57
What risk arises when iterating an object with for…in without guarding with hasOwnProperty?
Question 58
Why is Object.defineProperty useful when you need to hide metadata from typical iteration?
Question 59
When composing objects from smaller fragments, why is Object.assign({}, ...sources) safer than mutating the first source directly?
Question 60
Why is it important to document whether an object uses symbol keys?
Question 61
When cloning configuration with spread, why must you still be cautious with nested arrays inside the object?
Question 62
Why is Object.keys preferable to Object.values when you simply need the count of properties?
Question 63
Why is it beneficial to avoid mutating global configuration objects directly inside functions?
Question 64
Why might you convert objects to arrays using Object.entries before filtering by values?
Question 65
What benefit does Object.freeze provide when sharing configuration across worker threads?
Question 66
When should you choose hasOwnProperty over checking for undefined?
Question 67
Why is it useful to convert configuration objects to Maps when keys may not be strings?
Question 68
What advantage does destructuring assignment provide when extracting multiple properties in function parameters?
Question 69
Why does the order of spread operations matter when composing configuration objects?
Question 70
Why is Object.preventExtensions less strict than Object.seal?
Question 71
When iterating nested objects, why should you check whether a property is itself an object before recursing?
Question 72
Why is it risky to rely on enumeration order of object keys for logic such as caching or scheduling?
Question 73
Why might using Object.assign to add defaults inadvertently overwrite existing properties?
Question 74
When flattening nested objects for logging, why should you track the path (e.g., parent.child) alongside the value?
Question 75
Why is it important to clarify whether an API returns sealed objects?
