JavaScript Objects u0026 Arrays: Concepts and Methods Quiz Quiz

  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'?

    1. let car = { make: 'Toyota', model: 'Camry' };
    2. let car = ( make: 'Toyota', model: 'Camry' );
    3. let car = object(make: 'Toyota', model: 'Camry');
    4. let car = [ make: 'Toyota', model: 'Camry' ];
    5. let car = { make = 'Toyota', model = 'Camry' };
  2. Accessing Object Properties

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

    1. person(age)
    2. person::age
    3. person.age
    4. person-u003Eage
    5. person['ages']
  3. Adding Object Properties

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

    1. user-u003Ecity('London');
    2. user.city = 'London';
    3. user[city] = 'London';
    4. user.add('city', 'London');
    5. user.city=('London');
  4. Method Definition in Objects

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

    1. greet() =u003E { console.log('Hello'); }
    2. greet[] = function() { console.log('Hello'); }
    3. function greet() { console.log('Hello'); }
    4. greet: function() { console.log('Hello'); }
    5. greet = function() { console.log('Hello'); }
  5. The 'this' Keyword Context

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

    1. The function's prototype
    2. The parent object
    3. The current object calling the method
    4. An undefined context
    5. The global window object
  6. Prototypal Inheritance

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

    1. Create private variables
    2. Restrict access to methods
    3. Inherit properties and methods from another object
    4. Compile code at runtime
    5. Force strict typing
  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?

    1. [3, 2, 1]
    2. [2, 2, 2]
    3. [1, 2, 3, 6]
    4. [1, 4, 9]
    5. [2, 4, 6]
  8. Array filter() Method

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

    1. [5, 8]
    2. [12, 3]
    3. [5, 8, 12]
    4. [3, 5, 8, 12]
    5. [8, 12]
  9. Using Array reduce()

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

    1. [2, 4, 6]
    2. 123
    3. 6
    4. [1, 2, 3]
    5. 1, 2, 3
  10. Array forEach() Method

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

    1. It calls a provided function once for each array element
    2. It reduces the array to a single value
    3. It filters the array based on a condition
    4. It creates a new array by applying a function
    5. It sorts the array in place
  11. Array find() Method

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

    1. [25, 30]
    2. undefined
    3. 10
    4. 25
    5. 30
  12. Object Property Accessors

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

    1. obj[prop()]
    2. obj.prop
    3. obj[prop]
    4. obj#prop
    5. obj-u003Eprop
  13. Destructuring Arrays

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

    1. let (a, b) = [7, 8];
    2. let [a, b] = [7, 8, 9];
    3. let {a, b} = [7, 8, 9];
    4. let [a b] = [7, 8];
    5. let a, b = [7, 8];
  14. Destructuring Objects

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

    1. const [name] = person;
    2. const name = person['names'];
    3. const name = { person };
    4. const { name } = person;
    5. const name = person-u003Ename;
  15. Checking Property Existence

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

    1. obj.exists('id')
    2. obj.contains('id')
    3. obj.idExist()
    4. obj.hasOwnProperty('id')
    5. hasProperty(obj, 'id')
  16. Extending Object Prototypes

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

    1. Animal.prototype.speak = function() { console.log('Hi'); };
    2. Animal-u003Eprototype.speak = function() { console.log('Hi'); };
    3. Animal::speak = function() { console.log('Hi'); };
    4. Animal.prototype:speak = function() { console.log('Hi'); };
    5. Animal.speak = function() { console.log('Hi'); };