JavaScript MCQs with answers Page - 46

Here, you will find a collection of MCQ questions on JavaScript. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 833K Points
Coach

Q. What will be printed in the console on execution of the following JS code:

Code:
var array = [2, 4, 6, 7, 8, 10];
var myArr= array.filter(v => v / 2 === 0);

console.log(myArr);
  • (A) [7]
  • (B) [2, 4, 6, 8, 10]
  • (C) [2, 4, 6, 7, 8, 10]
  • (D) myArr

A

Admin • 833K Points
Coach

Q. What keyword is used to check whether a given property is valid or not?

  • (A) in
  • (B) is in
  • (C) exists
  • (D) lies

A

Admin • 833K Points
Coach

Q. How can a datatype be declared to be a constant type?

  • (A) const
  • (B) var
  • (C) let
  • (D) constant

A

Admin • 833K Points
Coach

Q. What will be the output of the following code snippet?

Code:
<script type="text/javascript">
a = 5 + "9";
document.write(a);
</script>
  • (A) Compilation Error
  • (B) 14
  • (C) Runtime Error
  • (D) 59

A

Admin • 833K Points
Coach

Q. What will be the output of the following code snippet?

Code:
<script type="text/javascript" language="javascript">
  
var a = "Scaler";
var result = a.substring(2, 4);
document.write(result);
  
</script>
  • (A) al
  • (B) ale
  • (C) cal
  • (D) caler

A

Admin • 833K Points
Coach

Q. When the switch statement matches the expression with the given labels, how is the comparison done?

  • (A) Both the datatype and the result of the expression are compared.
  • (B) Only the value of the expression is compared.
  • (C) Only the datatype of the expression is compared.
  • (D) None of the above.

A

Admin • 833K Points
Coach

Q. What will be the output of the following code snippet?

Code:
<script type="text/javascript" language="javascript">
 
var x=12;
var y=8;
var res=eval("x+y");
document.write(res);
 
</script>
  • (A) 20
  • (B) x+y
  • (C) 128
  • (D) None of the above

A

Admin • 833K Points
Coach

Q. What is the use of the <noscript> tag in Javascript?

  • (A) The contents are displayed by non-JS-based browsers.
  • (B) Clears all the cookies and cache.
  • (C) Both A and B.
  • (D) None of the above.

A

Admin • 833K Points
Coach

Q. What will be the output of the following code snippet?

Code:
(function(){
 setTimeout(()=> console.log(1),2000);
 console.log(2);
 setTimeout(()=> console.log(3),0);
 console.log(4);
})();
  • (A) 1 2 3 4
  • (B) 2 3 4 1
  • (C) 2 4 3 1
  • (D) 4 3 2 1

A

Admin • 833K Points
Coach

Q. What will be the output of the following code snippet?

Code:
(function(a){
 return (function(){
   console.log(a);
   a = 6;
 })()
})(21);
  • (A) 6
  • (B) NaN
  • (C) 21
  • (D) None of the above

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ