JavaScript MCQs with answers Page - 59

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. Where is the right place to insert JavaScript code?

  • (A) <head> section
  • (B) The two sections <head> and <body> are correct
  • (C) <body> section
  • (D) None of the above

A

Admin • 833K Points
Coach

Q. How do you write “Hello World” in an alert box?

  • (A) msg("Hello World");
  • (B) alert("Hello World");
  • (C) msgBox("Hello World");
  • (D) alertBox("Hello World");

A

Admin • 833K Points
Coach

Q. How to write an IF condition in JavaScript?

  • (A) if a = 2 then
  • (B) if a = 2
  • (C) if a == 2 else
  • (D) if (a == 2)

A

Admin • 833K Points
Coach

Q. How to write an IF condition to check if “a” is NOT equal to 2?

  • (A) if a <> 2
  • (B) if (a != 2)
  • (C) if a =! 2 then
  • (D) if (a <> 2)

A

Admin • 833K Points
Coach

Q. How to create a function in JavaScript?

  • (A) function f()
  • (B) function = f()
  • (C) function:f()
  • (D) None of the above

A

Admin • 833K Points
Coach

Q. What is the correct syntax for checking the value of “c”?

  • (A) if (c == "XYZ") then { } else { }
  • (B) if (c = "XYZ") then { } else { }
  • (C) if (c == "XYZ") { } else { }
  • (D) if (c = "XYZ") { } else { }

A

Admin • 833K Points
Coach

Q. How to declare an array of 10 elements in JavaScript?

  • (A) arr = new Array(10)
  • (B) var arr[10]
  • (C) var arr = array(10)
  • (D) var arr(10)

A

Admin • 833K Points
Coach

Q. How to get a random number between 5 and 9 inclusive?

  • (A) Math.floor((Math.random() * 5) + 4);
  • (B) Math.floor((Math.random() * 4) + 4);
  • (C) Math.floor((Math.random() * 4) + 5);
  • (D) Math.floor((Math.random() * 5) + 5);

A

Admin • 833K Points
Coach

Q. To check if three variables are equal, we are going to use_____?

  • (A) X = Y = Z
  • (B) (X == B) && (Y == Z)
  • (C) (X = B) && (Y = Z)
  • (D) (X == B) & (Y == Z)

A

Admin • 833K Points
Coach

Q. How many parameters can be passed to a function?

  • (A) Any
  • (B) As much as you want
  • (C) One for each argument
  • (D) One argument

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