20 Essential JavaScript MCQ You Should Know

JavaScript is a high-level, versatile programming language widely used for creating interactive and dynamic content on websites. It is primarily a client-side language that runs in web browsers to enhance user interfaces and experiences, but it can also be used on the server side with environments like Node.js.

In this article, we will see some JavaScript MCQ questions with answers that helps you to prepare for your next interview.

Multiple Choice Questions with Answers

Q1. Which of the following is not a reserved word in JavaScript?

  • interface
  • throws
  • program
  • short
View Answer

program


Q2. In JavaScript the x===y statement implies that

  • Both x and y are equal in value, type and reference address
  • Both are x and y are equal in value only
  • Both are equal in the value and data type
  • Both are not same at all
View Answer

Both are equal in the value and data type


Q3. What will typeof NaN return?

  • number
  • NaN
  • undefined
  • object
View Answer

number


Q4. What is the output of the following code?

console.log(typeof null);
  • null
  • undefined
  • object
  • number
View Answer

object


Q5. What does the Array.prototype.reduce method do?

  • It reduces the size of the array
  • It applies a function against an accumulator and each element in the array to reduce it to a single value
  • It reduces the number of elements in the array
  • It removes all duplicate elements from the array
View Answer

It applies a function against an accumulator and each element in the array to reduce it to a single value


Q6. Which of the following is not a valid JavaScript variable name?

  • _myVar
  • my-var
  • $myVar
  • myVar1
View Answer

my-var


Q7. What is the output of the following code?

function test() {
    console.log(this);
}
test();
  • undefined
  • null
  • Window object (in browsers)
  • test function
View Answer

Window object (in browsers)


Q8. Which of the following method is used to merge two arrays into one?

  • arr1 + arr2
  • arr1.concat(arr2)
  • arr1.push(arr2)
  • arr1.merge(arr2)
View Answer

arr1.concat(arr2)


Q9. What is the purpose of the Promise.all method?

  • To run multiple promises sequentially
  • To wait until all promises are either resolved or rejected
  • To run multiple promises and return the result of the first resolved promise
  • To handle the first rejected promise only
View Answer

To wait until all promises are either resolved or rejected


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

let a = [1, 2, 3];
let b = a;
b.push(4);
console.log(a);
  • [1, 2, 3]
  • [1, 2, 3, 4]
  • undefined
  • error
View Answer

[1, 2, 3, 4]


Q11. What is the purpose of the bind method in JavaScript?

  • To call a function with a specified this context
  • To create a new function with a specified this context and arguments
  • To call a function immediately with a specified this context
  • To add properties to an object
View Answer

To create a new function with a specified this context and arguments


Q12. What does the async keyword do when applied to a function?

  • It turns the function into a generator function
  • It makes the function execute synchronously
  • It allows the function to return a promise and to use await within it
  • It allows the function to be executed only in an async context
View Answer

It allows the function to return a promise and to use await within it


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

console.log("5" + 3);
  • 8
  • 53
  • error
  • undefined
View Answer

53


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

let a = 10;
(function() {
    console.log(a);
    let a = 20;
})();
  • 10
  • 20
  • undefined
  • ReferenceError
View Answer

ReferenceError


Q15. What is the output of the following code?

const obj = {
    a: 1,
    b: 2,
    c: 3
};
console.log(Object.keys(obj).length);
  • 1
  • 2
  • 3
  • 4
View Answer

3


Q16. Which of the following is true about the setTimeout function?

  • It immediately executes the specified function
  • It delays the execution of the specified function until the browser is idle
  • It executes the specified function after the given delay
  • It repeatedly executes the specified function at fixed intervals
View Answer

It executes the specified function after the given delay


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

function foo() {
    return {
        bar: "hello"
    };
}
console.log(foo().bar);
  • hello
  • undefined
  • null
  • Error
View Answer

hello


Q18. Which of the following statements is correct about async functions?

  • async functions return a promise
  • async functions must contain an await statement
  • async functions cannot be used as constructors
  • Both A and C
View Answer

Both A and C


Q19. What is the main purpose of the Event Loop in JavaScript?

  • To execute synchronous code
  • To handle asynchronous callbacks
  • To manage memory allocation
  • To parse JavaScript code
View Answer

To handle asynchronous callbacks


Q20. What is the output of the following code?

const a = [];
const b = a;
b.push(1);
console.log(a === b);
  • false
  • true
  • undefined
  • Error
View Answer

true