JavaScript MCQs with answers Page - 40

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. Variable declared is example of ___________ Variable.

Code:
function message() {
var name = "Bench";
alert(name);
}
  • (A) Local
  • (B) Global
  • (C) Semi-Global
  • (D) None of the above

A

Admin • 833K Points
Coach

Q. What is the output for code A and B?

Code:
Code A:
var x = 10;
y = --x + 1;
alert(y);

Code B:
var x = 10;
y = x-- + 1;
alert(y);
  • (A) 11,11
  • (B) 11,10
  • (C) 10,11
  • (D) 10,10

A

Admin • 833K Points
Coach

Q. A _________ is a group of reusable code which can be called anywhere in your program.

  • (A) switch
  • (B) loop
  • (C) function
  • (D) exception

A

Admin • 833K Points
Coach

Q. The most common way to define a function in JavaScript is by using the ____________ keyword.

  • (A) define
  • (B) function
  • (C) var
  • (D) fun

A

Admin • 833K Points
Coach

Q. Which statement required if you want to return a value from a function?

  • (A) return
  • (B) loop
  • (C) break
  • (D) continue

A

Admin • 833K Points
Coach

Q. The Function() constructor expects ______ number of string arguments

  • (A) 0
  • (B) 1
  • (C) 2
  • (D) any

A

Admin • 833K Points
Coach

Q. Which among the following regular expression specifies that password should contain at least one capital letter or one digit.

  • (A) /.*[A-Z].*/.test(password) && /.*[0-9].*/.test(password)
  • (B) /.*[A-Z].*/.test(password) || /.*[0-9].*/.test(password)
  • (C) /.*[A-Z][0-9].*/.test(password)
  • (D) None of the above

A

Admin • 833K Points
Coach

Q. Which of the following string will match the RegEx "((d).(dd))$"?

  • (A) 2.2
  • (B) 223.12
  • (C) 22.123
  • (D) 223.123

A

Admin • 833K Points
Coach

Q. Consider the following JavaScript statement containing regular expressions and check if the pattern matches?

Code:
var text = "lestfindcourse: 1, 2, 3";
var pattern = /d+/g;
  • (A) pattern.test(text)
  • (B) text.test(pattern)
  • (C) text.equals(pattern)
  • (D) text==pattern

A

Admin • 833K Points
Coach

Q. What would be the result of the following statement in JavaScript using regular expression methods?

  • (A) Throws an exception
  • (B) Returns [1,2,3,4,5,6,7,8,9]
  • (C) Returns ["123","456","789"]
  • (D) Returns ["123""456""789"]