JavaScript Objects & Arrays: Concepts and Methods Quiz — Questions & Answers

This quiz contains 16 questions. Below is a complete reference of all questions, answer choices, and correct answers. You can use this section to review after taking the interactive quiz above.

  1. Question 1: Object Literal Syntax

    Which of the following is the correct way to define an object literal representing a car with properties 'make' and 'model'?

    • let car = { make: 'Toyota', model: 'Camry' };
    • let car = ( make: 'Toyota', model: 'Camry' );
    • let car = object(make: 'Toyota', model: 'Camry');
    • let car = [ make: 'Toyota', model: 'Camry' ];
    • let car = { make = 'Toyota', model = 'Camry' };
    Show correct answer

    Correct answer: let car = { make: 'Toyota', model: 'Camry' };

  2. Question 2: Accessing Object Properties

    Given the object let person = { name: 'Anna', age: 22 }, how can you access the value of 'age'?

    • person(age)
    • person::age
    • person.age
    • person->age
    • person['ages']
    Show correct answer

    Correct answer: person.age

  3. Question 3: Adding Object Properties

    How can you add a property 'city' with the value 'London' to an existing object called user?

    • user->city('London');
    • user.city = 'London';
    • user[city] = 'London';
    • user.add('city', 'London');
    • user.city=('London');
    Show correct answer

    Correct answer: user.city = 'London';

  4. Question 4: Method Definition in Objects

    What is the correct way to define a method called greet inside an object?

    • greet() => { console.log('Hello'); }
    • greet[] = function() { console.log('Hello'); }
    • function greet() { console.log('Hello'); }
    • greet: function() { console.log('Hello'); }
    • greet = function() { console.log('Hello'); }
    Show correct answer

    Correct answer: greet: function() { console.log('Hello'); }

  5. Question 5: The 'this' Keyword Context

    In an object method, what does the 'this' keyword refer to?

    • The function's prototype
    • The parent object
    • The current object calling the method
    • An undefined context
    • The global window object
    Show correct answer

    Correct answer: The current object calling the method

  6. Question 6: Prototypal Inheritance

    What does prototypal inheritance in JavaScript allow an object to do?

    • Create private variables
    • Restrict access to methods
    • Inherit properties and methods from another object
    • Compile code at runtime
    • Force strict typing
    Show correct answer

    Correct answer: Inherit properties and methods from another object

  7. Question 7: Array map() Method

    If you use the map() method on an array [1, 2, 3] with a function that multiplies each value by 2, what is the resulting array?

    • [3, 2, 1]
    • [2, 2, 2]
    • [1, 2, 3, 6]
    • [1, 4, 9]
    • [2, 4, 6]
    Show correct answer

    Correct answer: [2, 4, 6]

  8. Question 8: Array filter() Method

    What will [5, 8, 12, 3].filter(x => x > 6) return?

    • [5, 8]
    • [12, 3]
    • [5, 8, 12]
    • [3, 5, 8, 12]
    • [8, 12]
    Show correct answer

    Correct answer: [8, 12]

  9. Question 9: Using Array reduce()

    What does the array method reduce() typically output when called on [1, 2, 3] with (acc, val) => acc + val as the callback?

    • [2, 4, 6]
    • 123
    • 6
    • [1, 2, 3]
    • 1, 2, 3
    Show correct answer

    Correct answer: 6

  10. Question 10: Array forEach() Method

    Which statement correctly describes what forEach() does to an array?

    • It calls a provided function once for each array element
    • It reduces the array to a single value
    • It filters the array based on a condition
    • It creates a new array by applying a function
    • It sorts the array in place
    Show correct answer

    Correct answer: It calls a provided function once for each array element

  11. Question 11: Array find() Method

    Given let arr = [10, 25, 30]; what does arr.find(x => x > 20) return?

    • [25, 30]
    • undefined
    • 10
    • 25
    • 30
    Show correct answer

    Correct answer: 25

  12. Question 12: Object Property Accessors

    Which syntax correctly accesses a property with a key stored in the variable 'prop' from an object 'obj'?

    • obj[prop()]
    • obj.prop
    • obj[prop]
    • obj#prop
    • obj->prop
    Show correct answer

    Correct answer: obj[prop]

  13. Question 13: Destructuring Arrays

    How do you use array destructuring to extract the first two values from [7, 8, 9] into variables a and b?

    • let (a, b) = [7, 8];
    • let [a, b] = [7, 8, 9];
    • let {a, b} = [7, 8, 9];
    • let [a b] = [7, 8];
    • let a, b = [7, 8];
    Show correct answer

    Correct answer: let [a, b] = [7, 8, 9];

  14. Question 14: Destructuring Objects

    Given const person = { name: 'Kai', age: 30 }, what is the correct way to extract the name property into a variable?

    • const [name] = person;
    • const name = person['names'];
    • const name = { person };
    • const { name } = person;
    • const name = person->name;
    Show correct answer

    Correct answer: const { name } = person;

  15. Question 15: Checking Property Existence

    What is the recommended way to check if an object obj has its own property 'id'?

    • obj.exists('id')
    • obj.contains('id')
    • obj.idExist()
    • obj.hasOwnProperty('id')
    • hasProperty(obj, 'id')
    Show correct answer

    Correct answer: obj.hasOwnProperty('id')

  16. Question 16: Extending Object Prototypes

    Which statement correctly adds a method speak() to the prototype of a constructor function Animal?

    • Animal.prototype.speak = function() { console.log('Hi'); };
    • Animal->prototype.speak = function() { console.log('Hi'); };
    • Animal::speak = function() { console.log('Hi'); };
    • Animal.prototype:speak = function() { console.log('Hi'); };
    • Animal.speak = function() { console.log('Hi'); };
    Show correct answer

    Correct answer: Animal.prototype.speak = function() { console.log('Hi'); };