Objects and array MCQs

JavaScript Function

1. What will be the output of the following code?


    const arr1 = [1, 2];
    const arr2 = [3, 4];
    const combined = [...arr1, ...arr2];
    console.log(combined);
    

2. What will be the output of the following code?


    const numbers = [1, 2, 3, 4];
    const lastNumber = numbers.pop();
    console.log(lastNumber);
    

3. What will be the result of destructuring the following object?


    const person = { name: 'Alice', age: 25 };
    const { name, age, gender } = person;
    console.log(gender);
    

4. What will be the output of the following code?


    const numbers = [1, 2, 3];
    const doubled = numbers.map(num => num * 2);
    console.log(doubled);
    

5. Can the spread operator (...) be used to create a deep copy of an object?

6. What will be the output of the following code?


    const numbers = [1, 2, 3, 4];
    const sum = numbers.reduce((acc, num) => acc + num, 0);
    console.log(sum);
    

7. Which of the following is a valid way to create an object in JavaScript?

8. Which loop is best used to iterate over the properties of an object?

9. What will be the output of the following code?


    const fruits = ['apple', 'banana', 'cherry'];
    console.log(fruits.length);
    

10. What will be the output of the following code?


    const numbers = [1, 2, 3, 4];
    const evenNumbers = numbers.filter(num => num % 2 === 0);
    console.log(evenNumbers);
    

11. What will be the output of the following code?


    const fruits = ['apple', 'banana', 'orange'];
    const lastFruit = fruits.pop();
    console.log(lastFruit);
    

12. What will be the output of the following code?


    const obj1 = { a: 1, b: 2 };
    const obj2 = { ...obj1, c: 3 };
    console.log(obj2);
    

13. What will be the output of the following code?


    const numbers = [1, 2, 3];
    const doubled = numbers.map(num => num * 2);
    console.log(doubled);
    

14. What will be the output of the following code?


    const person = { name: 'Alice', age: 25 };
    const keys = Object.keys(person);
    console.log(keys);
    

15. What will be the output of the following code?


    const numbers = [1, 2, 3, 4, 5];
    const evenNumbers = numbers.filter(num => num % 2 === 0);
    console.log(evenNumbers);
    

16. What will be the output of the following code?


    const arr = [1, 2, 3];
    const [x, y] = arr;
    console.log(x);
    

17. What will be the output of the following code?


    const numbers = [1, 2, 3, 4];
    const sum = numbers.reduce((acc, num) => acc + num, 0);
    console.log(sum);
    

18. What will be the output of the following code?


    const numbers = [1, 2, 3];
    const firstNumber = numbers.shift();
    console.log(firstNumber);
    

19. What will be the output of the following code?


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

20. What will be the output of the following code?


    const user = { name: 'John', age: 30 };
    const { name } = user;
    console.log(name);
    

2 comments

  1. question no 5 selecting correct option but is showing wrong!
    1. i have just done this part and all there is no error in question no. 5
Your comment will be visible after approval.
© TechTestLog. All rights reserved. Premium By Raushan Design
//My script