Which syntax correctly accesses a property named `name` in an object called `person`?
A
person(name) B
person.name C
person->name D
person::name
Analysis & Theory
`person.name` is the correct dot notation to access the `name` property.
Which syntax is used to access a property using a variable key?
A
person.key B
person->key C
person[key] D
person{key}
Analysis & Theory
Bracket notation (`person[key]`) allows dynamic access using a variable.
What will `Object.keys(obj)` return?
A
An array of object values B
An array of object keys C
A string of object keys D
The number of properties
Analysis & Theory
`Object.keys(obj)` returns an array of the object's own enumerable property names.
What does `Object.values(obj)` return?
A
Keys of the object B
Methods of the object C
Values of the object D
Number of keys
Analysis & Theory
`Object.values(obj)` returns an array of the object's values.
How do you check if an object has a specific property?
A
`obj.exists('key')` B
`obj.includes('key')` C
`obj.hasOwnProperty('key')` D
`obj.contains('key')`
Analysis & Theory
`obj.hasOwnProperty('key')` checks if the object has that property directly.
What will this code output?
```javascript
let car = { brand: 'Toyota' };
console.log('brand' in car);
```
A
undefined B
false C
true D
Error
Analysis & Theory
`'brand' in car` returns `true` because the property exists.
Which method returns both keys and values from an object?
A
Object.entries(obj) B
Object.values(obj) C
Object.keys(obj) D
Object.pairs(obj)
Analysis & Theory
`Object.entries(obj)` returns an array of [key, value] pairs.
How can you delete a property from an object?
A
`remove obj.key` B
`delete obj.key` C
`obj.key = null` D
`obj.key.destroy()`
Analysis & Theory
`delete obj.key` removes the property from the object.
What will `typeof obj.key` return if `key` doesn't exist?
A
null B
false C
undefined D
error
Analysis & Theory
Accessing a non-existent property returns `undefined`.
Which statement correctly checks if `person.age` is not `undefined`?
A
`if (person.age)` B
`if (typeof person.age !== 'undefined')` C
`if (person.age == null)` D
`if (person.age === 'undefined')`
Analysis & Theory
This ensures the property exists and is not `undefined` using `typeof`.