feat(curriculum): create objects quiz (#56583)

Co-authored-by: Krzysztof G. <60067306+gikf@users.noreply.github.com>
Co-authored-by: Naomi <accounts+github@nhcarrigan.com>
This commit is contained in:
Tunmise Ogunniyi
2024-10-11 16:04:55 +02:00
committed by GitHub
co-authored by Krzysztof G. Naomi
parent fa7f31c50d
commit f37cd31880
@@ -17,439 +17,469 @@ Answer all of the questions below correctly to pass the quiz.
#### --text--
Placeholder question
Which of the following does not describe an object in Javascript?
#### --distractors--
Placeholder distractor 1
A collection of key-value pairs
---
Placeholder distractor 2
A container for properties and methods
---
Placeholder distractor 3
One of Javascript's data types
#### --answer--
Placeholder answer
One of Javascript's primitives
### --question--
#### --text--
Placeholder question
Which of the following object definitions is invalid?
#### --distractors--
Placeholder distractor 1
`const obj = { key: "some-value" }`
---
Placeholder distractor 2
`const obj = { "some-value": key }`
---
Placeholder distractor 3
`const obj = { key: () => "some-value" }`
#### --answer--
Placeholder answer
`const obj = { key(): "some-value" }`
### --question--
#### --text--
Placeholder question
Which of the following correctly accesses the value of the `key` property in the object below:
```js
const obj = { key: "some-value" }
```
#### --distractors--
Placeholder distractor 1
`obj -> key`
---
Placeholder distractor 2
`obj#key`
---
Placeholder distractor 3
`obj[key]`
#### --answer--
Placeholder answer
`obj.key`
### --question--
#### --text--
Placeholder question
Which of the following correctly accesses the value of the `street` property in the object below?
```js
const person = {
address: {
street: "sample-street"
}
}
```
#### --distractors--
Placeholder distractor 1
`person -> address -> street`
---
Placeholder distractor 2
`person#address#street`
---
Placeholder distractor 3
`person[address.street]`
#### --answer--
Placeholder answer
`person["address"]["street"]`
### --question--
#### --text--
Placeholder question
Which of the following property key can only be used with a bracket notation as opposed to dot notation?
#### --distractors--
Placeholder distractor 1
A property key that is known and static
---
Placeholder distractor 2
A property key nested in multiple levels of the object
---
Placeholder distractor 3
A property key that might not exist in the object
#### --answer--
Placeholder answer
A property key that is dynamic
### --question--
#### --text--
Placeholder question
Which of the following correctly accesses the value of `name` property via destructuring in the object below?
```js
const person = { name: "John" }
```
#### --distractors--
Placeholder distractor 1
`const name = person.name`
---
Placeholder distractor 2
`const name = person["name"]`
---
Placeholder distractor 3
`const { ...name } = person`
#### --answer--
Placeholder answer
`const { name } = person`
### --question--
#### --text--
Placeholder question
Which of the following correctly accesses the value of `street` property via destructuring in the object below?
```js
const person = {
address: {
street: "sample-street"
}
}
```
#### --distractors--
Placeholder distractor 1
`const name = person.address.street`
---
Placeholder distractor 2
`const name = person["address"]["street"]`
---
Placeholder distractor 3
`const { address: street } = person`
#### --answer--
Placeholder answer
`const { address: { street } } = person`
### --question--
#### --text--
Placeholder question
How do you assign a default value of `"defaultValue"` to a property key accessed via destructuring?
#### --distractors--
Placeholder distractor 1
`const key = object.key && "defaultValue"`
---
Placeholder distractor 2
`const key = object.key || "defaultValue"`
---
Placeholder distractor 3
`const { key: "defaultValue" } = object `
#### --answer--
Placeholder answer
`const { key = "defaultValue" } = object`
### --question--
#### --text--
Placeholder question
Which of the following objects does not inherit from `Object.prototype`?
#### --distractors--
Placeholder distractor 1
`const obj = Object.create(undefined)`
---
Placeholder distractor 2
`const obj = new Object(null)`
---
Placeholder distractor 3
`const obj = { proto: undefined }`
#### --answer--
Placeholder answer
`const obj = Object.create(null}`
### --question--
#### --text--
Placeholder question
Which of the following cannot be an object prototype?
#### --distractors--
Placeholder distractor 1
`Math`
---
Placeholder distractor 2
`Date`
---
Placeholder distractor 3
`null`
#### --answer--
Placeholder answer
`undefined`
### --question--
#### --text--
Placeholder question
Which of the following correctly creates an object with the prototype below:
```js
const samplePrototype = {
doSomething: () => {}
}
```
#### --distractors--
Placeholder distractor 1
`const obj = { proto: samplePrototype }`
---
Placeholder distractor 2
`const obj = { prototype: samplePrototype }`
---
Placeholder distractor 3
`const obj = new Object(samplePrototype)`
#### --answer--
Placeholder answer
`const obj = Object.create(samplePrototype)`
### --question--
#### --text--
Placeholder question
Which of the following keywords is used to identify a getter in an Object?
#### --distractors--
Placeholder distractor 1
`getter`
---
Placeholder distractor 2
`get_`
---
Placeholder distractor 3
`_get`
#### --answer--
Placeholder answer
`get`
### --question--
#### --text--
Placeholder question
Which of the following keywords is used to identify a setter in an Object?
#### --distractors--
Placeholder distractor 1
`setter`
---
Placeholder distractor 2
`set_`
---
Placeholder distractor 3
`_set`
#### --answer--
Placeholder answer
`set`
### --question--
#### --text--
Placeholder question
Which of the following is true about object setters?
#### --distractors--
Placeholder distractor 1
An object setter must be called with a parenthesis
---
Placeholder distractor 2
An object setter must be defined with the same name as the property it sets
---
Placeholder distractor 3
An object setter must be accompanied by a getter
#### --answer--
Placeholder answer
An object setter must be defined with exactly one argument
### --question--
#### --text--
Placeholder question
Which of the following is the correct syntax for optional chaining?
#### --distractors--
Placeholder distractor 1
`object.key`
---
Placeholder distractor 2
`object.["key"]`
---
Placeholder distractor 3
`object.?key`
#### --answer--
Placeholder answer
`object?.key`
### --question--
#### --text--
Placeholder question
What is the difference between enumerable and non-enumerable properties in an object?
#### --distractors--
Placeholder distractor 1
Enumerable properties are owned by the object while non-enumerable properties are not.
---
Placeholder distractor 2
Enumerable properties are defined by the object while non-enumerable properties can only be inherited.
---
Placeholder distractor 3
Enumerable properties can be accessed via dot notation while non-enumerable properties can only be accessed via bracket notation
#### --answer--
Placeholder answer
Enumerable properties are properties whose internal enumerable flag is set to true while non-enumerable properties' internal enumerable flag is set to false
### --question--
#### --text--
Placeholder question
What is the difference between `Object.keys()` and `Object.getOwnPropertyNames()`?
#### --distractors--
Placeholder distractor 1
`Object.keys()` returns all the properties prefixed with the word `key_` while `Object.getOwnPropertyNames()` returns all object properties regardless of prefix.
---
Placeholder distractor 2
`Object.keys()` returns all properties inherited and owned by the object while `Object.getOwnPropertyNames()` only returns properties owned by the object.
---
Placeholder distractor 3
`Object.keys()` and `Object.getOwnPropertyNames()` will always return the same list of properties.
#### --answer--
Placeholder answer
`Object.keys()` returns only enumerable properties of an object while `Object.getOwnPropertyNames()` returns enumerable and non-enumerable properties except for those which use Symbol.
### --question--
#### --text--
Placeholder question
Which of the following is true for an object sealed with `Object.seal`?
#### --distractors--
Placeholder distractor 1
Values of existing properties cannot be changed
---
Placeholder distractor 2
Values of existing properties can be changed but doing this will unseal the object
---
Placeholder distractor 3
New properties can be added but existing properties can not be removed
#### --answer--
Placeholder answer
New properties cannot be added and existing properties cannot be removed
### --question--
#### --text--
Placeholder question
Which of the following is true for an object frozen with `Object.freeze`?
#### --distractors--
Placeholder distractor 1
New properties can be added but existing properties can not be removed
---
Placeholder distractor 2
New properties can be added but doing this will unfreeze the object
---
Placeholder distractor 3
Values of existing properties can be changed but doing this will unfreeze the object
#### --answer--
Placeholder answer
Values of existing properties cannot be changed
### --question--
#### --text--
Placeholder question
What is the right way to completely remove a property from an object?
#### --distractors--
Placeholder distractor 1
`Object.delete(object, propertyKey)`
---
Placeholder distractor 2
`remove object.propertyKey`
---
Placeholder distractor 3
`object.propertyKey = undefined`
#### --answer--
Placeholder answer
`delete object.propertyKey`