MCQs on Advanced Object Features | JavaScript Advanced

Master Chapter 18: Advanced Object Features with These 30 MCQs
Dive into Chapter 18 and boost your expertise in JavaScript object techniques. Explore Object Destructuring, Spread and Rest Operators, Object Property Shorthand, Computed Properties, and the utility methods Object.keys, Object.values, and Object.entries. Test your knowledge now!


Object Destructuring (MCQs 1-8)

  1. What is the correct syntax for destructuring properties from an object?
    • A) const {name, age} = object;
    • B) let object = {name, age};
    • C) const object = [name, age];
    • D) let {name, age} = object[];
  2. In the code const {x, y} = {x: 10, y: 20};, what is the value of y?
    • A) undefined
    • B) null
    • C) 10
    • D) 20
  3. Which syntax allows renaming variables while destructuring?
    • A) const {x, y: z} = obj;
    • B) const {x, y = z} = obj;
    • C) let {x as y} = obj;
    • D) let obj = {x: y};
  4. How do you assign default values during destructuring?
    • A) const {a = 5} = obj;
    • B) let {a: 5} = obj;
    • C) const obj = {a || 5};
    • D) let obj[a] = 5;
  5. In nested destructuring, how would you access a nested property?
    • A) const {user: {name}} = data;
    • B) const {name.user} = data;
    • C) const name = user.data;
    • D) let data = {name.user};
  6. What happens if a destructured property does not exist in the object?
    • A) Throws an error
    • B) Undefined is returned
    • C) Default value is mandatory
    • D) Value becomes null
  7. Which is invalid destructuring syntax?
    • A) const {x, y} = obj;
    • B) let {x, ...y} = obj;
    • C) let {x: y} = obj;
    • D) const [x, y] = obj;
  8. Can destructuring be used in function parameters?
    • A) Yes, with objects
    • B) No, only for arrays
    • C) Only if default values are present
    • D) No, destructuring is not allowed

Spread and Rest Operators (MCQs 9-16)

  1. Which symbol represents the spread operator in JavaScript?
    • A) ...
    • B) ,,
    • C) ::
    • D) --
  2. How can you merge two objects using the spread operator?
    • A) const obj3 = {...obj1, ...obj2};
    • B) let obj3 = [obj1, obj2];
    • C) let obj3 = obj1 + obj2;
    • D) const obj3 = obj1.concat(obj2);
  3. What does the rest operator do?
    • A) Merges objects
    • B) Gathers remaining elements into an array
    • C) Extracts specific elements
    • D) Combines keys and values
  4. Which of the following is valid syntax for the rest operator?
    • A) const {...rest} = obj;
    • B) let obj = {rest...};
    • C) let rest = {...obj};
    • D) const obj = {..., rest};
  5. What will const [first, ...rest] = [1, 2, 3]; return for rest?
    • A) [1, 2, 3]
    • B) [2, 3]
    • C) [1]
    • D) []
  6. How can you copy an object using the spread operator?
    • A) const copy = {...original};
    • B) const copy = {original};
    • C) let copy = [...original];
    • D) let copy = {original...};
  7. Can the spread operator be used with strings?
    • A) Yes, it splits characters
    • B) No, only arrays
    • C) Only for concatenation
    • D) It works with objects, not strings
  8. Which of these is NOT a valid use case for the rest operator?
    • A) Gathering function arguments
    • B) Copying arrays
    • C) Combining multiple objects
    • D) Filtering remaining elements

Object Property Shorthand and Computed Properties (MCQs 17-24)

  1. What does the property shorthand allow?
    • A) Simplifies object creation when property names match variables
    • B) Creates default values
    • C) Automatically generates keys
    • D) Reassigns variables
  2. Which is a valid shorthand property?
    • A) const obj = {name, age};
    • B) const obj = {name: name, age};
    • C) let obj = {name: "name", age};
    • D) let obj = {"name": name, age};
  3. What does a computed property key look like?
    • A) const obj = {[key]: value};
    • B) const obj = {key: value};
    • C) let obj = {key[]: value};
    • D) const obj = {value[key]};
  4. Can computed properties include expressions?
    • A) Yes, inside square brackets
    • B) No, only static strings are allowed
    • C) Only if they are integers
    • D) Yes, but only as values
  5. What will this output: const obj = {[1+2]: 'value'};?
    • A) {3: 'value'}
    • B) {'3': 'value'}
    • C) {[1+2]: 'value'}
    • D) Throws an error
  6. Which is NOT true for computed properties?
    • A) They allow dynamic keys
    • B) They require ES6+ syntax
    • C) Only one computed property is allowed per object
    • D) Can use variables as keys
  7. In property shorthand, how do you assign a variable to a property?
    • A) Use the variable name directly
    • B) Use the => operator
    • C) Wrap the variable in square brackets
    • D) Assign using = key
  8. What is the benefit of using shorthand properties?
    • A) Reduces repetition
    • B) Increases object size
    • C) Creates unique keys
    • D) Prevents default values

Object.keys, Object.values, Object.entries (MCQs 25-30)

  1. What does Object.keys(obj) return?
    • A) An array of keys
    • B) An array of values
    • C) Key-value pairs
    • D) An object
  2. Which method retrieves values from an object?
    • A) Object.values(obj)
    • B) Object.keys(obj)
    • C) Object.props(obj)
    • D) Object.entries(obj)
  3. What does Object.entries(obj) return?
    • A) An array of key-value pairs
    • B) A list of keys
    • C) A map of values
    • D) A concatenated string
  4. How can you iterate over Object.entries(obj)?
    • A) Using for...of
    • B) Using for...in
    • C) Using obj.map()
    • D) Using obj.entries()
  5. Which of these is a valid use case for Object.keys()?
    • A) Iterating over property names
    • B) Sorting object values
    • C) Extracting all methods
    • D) Checking object size
  6. What happens if Object.values() is called on a non-object?
    • A) Throws a TypeError
    • B) Returns undefined
    • C) Converts input to object
    • D) Returns an empty array

Answer Key

QNoAnswer (Option with text)
1A) const {name, age} = object;
2D) 20
3A) const {x, y: z} = obj;
4A) const {a = 5} = obj;
5A) const {user: {name}} = data;
6B) Undefined is returned
7D) const [x, y] = obj;
8A) Yes, with objects
9A) ...
10A) const obj3 = {...obj1, ...obj2};
11B) Gathers remaining elements into an array
12A) const {...rest} = obj;
13B) [2, 3]
14A) const copy = {...original};
15A) Yes, it splits characters
16C) Combining multiple objects
17A) Simplifies object creation when property names match variables
18A) const obj = {name, age};
19A) const obj = {[key]: value};
20A) Yes, inside square brackets
21A) {3: 'value'}
22C) Only one computed property is allowed per object
23A) Use the variable name directly
24A) Reduces repetition
25A) An array of keys
26A) Object.values(obj)
27A) An array of key-value pairs
28A) Using for...of
29A) Iterating over property names
30C) Converts input to object

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top