Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What is array destructuring?

View

What is the result of the following code?

View

How do you assign default values when destructuring an array?

View

What is the result of the following code?

View

Which of the following is an example of object destructuring?

View

What does the following code return?

View

How do you rename variables when destructuring an object?

View

What happens if you try to destructure a property that doesn’t exist?

View

What is the result of the following code?

View

What does the following code return?

View

What is array destructuring?

A syntax to unpack values from arrays into variables
A method to copy arrays
A method to modify arrays
A way to delete elements from an array

What is the result of the following code?

const arr = [1, 2, 3]; const [a, b, c] = arr; console.log(a, b, c);

1 2 3
undefined undefined undefined
1 3 2
3 2 1

How do you assign default values when destructuring an array?

const [a, b = 2] = arr;
const { a, b = 2 } = arr;
const arr = [a, b = 2];
const a, b = arr;

What is the result of the following code?

const obj = { x: 10, y: 20 }; const { x, y } = obj; console.log(x, y);

10 20
undefined undefined
x y
20 10

Which of the following is an example of object destructuring?

const { a, b } = obj;
const [a, b] = arr;
const a = obj.a; const b = obj.b;
const a = arr[0]; const b = arr[1];

What does the following code return?

const arr = [1, 2, 3]; const [a, , b] = arr; console.log(a, b);

1 3
1 2
2 3
undefined

How do you rename variables when destructuring an object?

const { oldName: newName } = obj;
const [oldName: newName] = obj;
const { newName = obj.oldName };
const newName = obj[oldName];

What happens if you try to destructure a property that doesn’t exist?

The variable is set to undefined
An error is thrown
The variable is set to null
The entire object is returned

What is the result of the following code?

const obj = { name: "Alice", age: 25 }; const { name, age, location = "unknown" } = obj; console.log(location);

unknown
undefined
Error
25

What does the following code return?

const arr = [1, 2, 3]; const [a, b, c = 4] = arr; console.log(c);

3
4
undefined
Error