JavaScript Objects u0026 Arrays Essentials Quiz Quiz

Test your knowledge of JavaScript object literals, properties, methods, prototypes, inheritance, and common array methods. This quiz helps reinforce the foundations for working with complex data in JavaScript.

  1. Object Literal Syntax

    What is the correct way to define an object named 'car' with a property 'color' set to 'red' using object literal syntax?

    1. var car = [ color = 'red' ];
    2. object car = ('color' : 'red');
    3. let car = color: 'red';
    4. const car = { color: 'red' };
    5. const car = ( color: 'red' );
  2. Accessing Properties

    Given const user = { name: 'Sam', age: 20 }, how do you access the 'name' property?

    1. user('name')
    2. user[name]
    3. user:name
    4. user-u003Ename
    5. user.name
  3. Adding a New Property

    How do you add a new property called 'isAdmin' set to true to an existing object 'employee'?

    1. employee('isAdmin') = true;
    2. employee.isAdmin = true;
    3. employee-u003EisAdmin true;
    4. employee[isAdmin] = true;
    5. employee.add('isAdmin', true);
  4. Method Definition in Objects

    Which is the correct way to define a method 'greet' inside an object 'person' that logs 'Hello'?

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

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

    1. The global object always
    2. The parent class
    3. A random variable in the scope
    4. The most recent function called
    5. The object the method belongs to
  6. Prototypal Inheritance

    What is the main purpose of prototypes in JavaScript?

    1. To define variable scopes
    2. To declare constants
    3. To attach event listeners
    4. To initialize array values
    5. To enable inheritance between objects
  7. Array Mapping

    What is the output of [2, 4, 6].map(n =u003E n * 2)?

    1. [2, 8, 36]
    2. [2, 6, 12]
    3. [2, 4, 6, 2, 4, 6]
    4. [4, 6, 8]
    5. [4, 8, 12]
  8. Filtering Arrays

    Which array method returns a new array containing elements that pass a test function?

    1. join()
    2. reduce()
    3. forEach()
    4. filter()
    5. splice()
  9. Reducing Arrays

    What does the reduce() method do when called on an array like [1, 2, 3]?

    1. Combines array elements into a single value
    2. Turns the array into a string
    3. Increases the length of the array
    4. Filters out duplicate values
    5. Sorts the array by default
  10. Using forEach

    What is the primary purpose of the forEach() method in JavaScript arrays?

    1. To filter elements based on a condition
    2. To execute a provided function once for each array element
    3. To find the first matching element in the array
    4. To add new elements to the array
    5. To combine array elements into a string
  11. Finding Elements

    Which method would you use to get the first element greater than 10 in an array?

    1. sort()
    2. pop()
    3. filter()
    4. find()
    5. map()
  12. Array Destructuring

    How do you assign the first and second values of the array [5, 10] to variables a and b?

    1. a, b = 5, 10;
    2. var a = [5], b = [10];
    3. const (a, b) = [5, 10];
    4. const [a, b] = [5, 10];
    5. let a, b = [5, 10];
  13. Object Destructuring

    Given const point = { x: 2, y: 3 }, how do you assign 2 to variable x and 3 to y?

    1. let [x, y] = point;
    2. const { x, y } = point;
    3. const x, y = point;
    4. object {x, y} = point;
    5. point = (x, y);
  14. Checking Own Properties

    What method can be used to check if an object has its own property called 'model'?

    1. ownsProperty('model')
    2. getProperty('model')
    3. propertyExists('model')
    4. checkProperty('model')
    5. hasOwnProperty('model')
  15. Prototype Chain Lookup

    If a property is not found directly on an object, where does JavaScript look for it next?

    1. It throws an error instantly
    2. On the object's prototype
    3. In the object's constructor
    4. In the global namespace
    5. In the array of methods
  16. Object Property Shorthand

    Given variables a = 2 and b = 3, how can you define an object using property shorthand?

    1. const obj = (a, b);
    2. const obj = [a, b];
    3. let obj = { :a, :b };
    4. const obj = { a: a + b: b };
    5. const obj = { a, b };