JavaScript JunkiesJavaScript Junkies Unleash Your Coding Superpowers with JavaScript Junkies

Top JavaScript Multiple Choice Questions and Answers

What is the correct way to declare a JavaScript variable?

  • a) variable myVar;
  • b) var myVar; 
  • c) v myVar; 
  • d) let myVar;

Answer: b) var myVar;


What is the output of the following code?

console.log(5 + "2");
  • a) 7
  • b) 52
  • c) NaN
  • d) Error

Answer: b) 52


Which method is used to add an element to the end of an array?

  • a) push() 
  • b) pop() 
  • c) shift() 
  • d) unshift() 

Answer: a) push()


What does the typeof operator in JavaScript return? 

  • a) The data type of a variable 
  • b) The value of a variable 
  • c) The size of a variable 
  • d) The scope of a variable 

Answer: a) The data type of a variable


How do you write a comment in JavaScript?

a) //This is a comment 
b) !--This is a comment--> 
c) /*This is a comment*/ 
d) #This is a comment

Answer: a) //This is a comment


What is the correct way to write a JavaScript array?

  • a) [1, 2, 3, 4]
  • b) {1, 2, 3, 4}
  • c) (1, 2, 3, 4)
  • d) <1, 2, 3, 4>

Answer: a) [1, 2, 3, 4]


How do you convert a string to an integer in JavaScript?

a) parseInt()
b) parseFloat()
c) toString()
d) toFixed()

Answer: a) parseInt()


Which operator is used to concatenate strings in JavaScript?

  • a) +
  • b) – 
  • c) * 
  • d) /

Answer: a) +

What is the scope of a variable declared with the let keyword?

  • a) Block scope 
  • b) Global scope 
  • c) Local scope 
  • d) Function scope 

Answer: a) Block scope

Press ESC to close