JavaScript MCQs with answers Page - 51

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. Find output of below Javascript addition code

Code:
document.write("2 plus 2 is " + 2 + 2);
  • (A) 4
  • (B) 2 plus 2 is 4
  • (C) 2 plus 2 is 22
  • (D) 2 plus 2 is 2 + 2

A

Admin • 833K Points
Coach

Q. Find output of below Javascript code

Code:
<script>
document.write(2+2 + " = 2 plus 2");
</script>
  • (A) 4 + = 2 plus 2
  • (B) 4 = 2 plus 2
  • (C) 2+2+ = 2 plus 2
  • (D) Syntax Error

A

Admin • 833K Points
Coach

Q. What is the output of below Javascript code if user keeps the default value of prompt box?

Code:
<script>
var question = "Your species?";
var defaultAns = "human";
var out = prompt(question, defaultAns);
document.write(out);
</script>
  • (A) human
  • (B) Error
  • (C) NaN
  • (D) Nothing is printed

A

Admin • 833K Points
Coach

Q. What if we put ; after if? does it really affect? Find the output of below Javascript

Code:
<script>
 var a = 10;
 if(a == 20);
 document.write(a);
</script>

  • (A) 10
  • (B) 20
  • (C) Nothing is printed
  • (D) Error

A

Admin • 833K Points
Coach

Q. What if we put ++ operator inside if condition? find the output of below code

Code:
<script>
var a = 10;
if(a == a++)
document.write(a);
</script>
  • (A) 10
  • (B) 11
  • (C) Error
  • (D) Nothing is printed

A

Admin • 833K Points
Coach

Q. Find the output of below Javascript

Code:
<script>
var a = 10;
if(a == a++);
{
document.write(a);
}
</script>
  • (A) 10
  • (B) 11
  • (C) Error
  • (D) Nothing is printed

A

Admin • 833K Points
Coach

Q. Find the output of below for loop in Javascript

Code:
<script>
for(var i=0;i<5;i++)
{
    document.write(i++);
}
</script>
  • (A) 024
  • (B) 135
  • (C) 012345
  • (D) 01234

A

Admin • 833K Points
Coach

Q. Can we put ; after for loop in Javascript? find the output of below code

Code:
<script>
for(var i=0;i<5;i++);
{
    document.write(i++);
}
</script>
  • (A) 5
  • (B) 024
  • (C) 135
  • (D) Compilation Error

A

Admin • 833K Points
Coach

Q. Is it mandatory to put all three conditions in for loop? find the output of below Javascript code

Code:
<script>
for(var i=0;i++<5; )
{
    document.write(i);
}
  • (A) 1234
  • (B) 01234
  • (C) 12345
  • (D) Compilation Error

A

Admin • 833K Points
Coach

Q. Example of arrays in Javascript. Find output of below code

Code:
<script>
var firstNames = ["c", "c++", "java", "python", "perl"];
for (var i = 0; i < firstNames.length; i++) {
if(i%2===0)
continue;
document.write(i);
}
</script>
  • (A) 13
  • (B) 135
  • (C) 01234
  • (D) 012345

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