curriculum/challenges/english/blocks/quiz-javascript-objects/66edcd0ecb4b25dc64a34804.md
To pass the quiz, you must correctly answer at least 18 of the 20 questions below.
Which of the following does NOT describe an object in JavaScript?
A collection of key-value pairs.
A container for properties and methods.
A non-primitive data type.
A primitive data type.
Which of the following object definitions is invalid?
const book = { "pages": 255 };
const car = { year: 2025 };
const person = { "name": "nora" };
const product = { color: blue };
How can you access the job property of this person object?
let person = { job: "Software Developer" };
person -> job
person#job
person[job]
person.job
How can you access the street property of the person object below?
const person = {
address: {
street: "sample-street"
}
};
person -> address -> street
person#address#street
person[address.street]
person["address"]["street"]
Which of these property keys can only be accessed using bracket notation?
A property key that is known and static.
A property key that is nested within multiple levels of an object.
A property key that might not exist in the object.
A property key that is dynamic.
Which of the following correctly uses destructuring to access the name property of the person object below?
const person = { name: "John" }
const name = person.name;
const name = person["name"];
const { ...name } = person;
const { name } = person;
Which of the following correctly uses destructuring to access the flour property of the recipe object below?
const recipe = {
ingredients: {
flour: "2 cups",
sugar: "1 cup"
}
};
const flour = recipe.ingredients.flour;
const flour = recipe["ingredients"]["flour"];
const { ingredients: flour } = recipe;
const { ingredients: { flour } } = recipe;
How can you assign a default value to a property key when using destructuring in JavaScript?
const key = object.key && "defaultValue";
const key = object.key || "defaultValue";
const { key: "defaultValue" } = object;
const { key = "defaultValue" } = object;
How can you check if a car object has a year property?
year.hasProperty("car");
car.hasProperty("year");
car.hasOwnProperty(year);
car.hasOwnProperty("year");
What is an object method?
A string associated with an object.
An array associated with an object.
A number associated with an object.
A function associated with an object.
How can you call the add method of this calculator object to add the numbers 10 and 7?
const calculator = {
add: function(a, b) {
return a + b;
}
};
calculator#add(10, 7);
calculator.call(add(10, 7));
add.calculator(10, 7);
calculator.add(10, 7);
Which operator removes a property from an object?
remove
erase
discard
delete
How can you check if a score property exists in a player object?
player in "score"
player in score
score in player
"score" in player
How can you create a new empty object in JavaScript?
object() new
new object()
Object() new
new Object()
What is the correct syntax for using optional chaining in JavaScript?
object?key
object.["key"]
object.?key
object?.key
What is optional chaining used for in JavaScript?
Used to define variables with default values.
Used to define optional methods within an object that may or may not be called.
Used to write more concise code by chaining multiple method calls together in a single statement.
Used to safely access properties of an object that might be null or undefined.
What method is used to convert a JavaScript object into a JSON string?
Stringify.toJSON()
JSON.toObject()
Object.toJSON()
JSON.stringify()
What method converts a JSON string back into a JavaScript object?
JSON.toObject()
JSON.convert()
JSON.object()
JSON.parse()
Which one of these options accesses the color property of a toy object using bracket notation?
toy.color
toy[color]
color[toy]
toy["color"]
How can you access the home phone of this learner object in JavaScript using dot notation?
const learner = {
name: "Nora",
age: 45,
contact: {
email: "[email protected]",
phone: {
home: "123-456-7890",
work: "098-765-4321"
}
}
};
learner.name.phone.home
learner.email.work
learner.contact.home
learner.contact.phone.home