JavaScript MCQs with answers Page - 4

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 • 833.24K Points
Coach

Q. Consider the following code snippet :
The state stored in q is :

Code:
var p = counter(), q = counter(); 
p.count()
q.count() 
p.reset() 
p.count() 
q.count()
  • (A) Undefined
  • (B) Null
  • (C) 0
  • (D) 1

A

Admin • 833.24K Points
Coach

Q. What is the difference between the two lines given below ?

Code:
!!(object1 && object2);
(object1 && object2);
  • (A) Both the lines checks just for the existence of the object alone
  • (B) The first line results in a real boolean value whereas the second line merely checks for the existence of the objects
  • (C) Both the lines result in a boolean value “False”
  • (D) Both the lines result in a boolean value “True”

A

Admin • 833.24K Points
Coach

Q. For the below mentioned code snippet:
The equivalent statement is

Code:
var obj = new Object();
  • (A) Object obj=new Object();
  • (B) var obj= new Object;
  • (C) var obj;
  • (D) var obj = Object();

A

Admin • 833.24K Points
Coach

Q. If you have a function f and an object o, you can define a method named m of o with

  • (A) obj=fun.meth;
  • (B) obj=fun;
  • (C) obj.meth=meth.fun;
  • (D) obj.meth=fun;

A

Admin • 833.24K Points
Coach

Q. The one-liner code that concatenates all strings passed into a function is

  • (A) function concatenate() { return String.concat.apply(', arguments); }
  • (B) function concatenate() { return String.prototype.concat(', arguments); }
  • (C) function concatenate() { return String.prototype.concat.apply(', arguments); }
  • (D) function concatenate() { return String.prototype.apply(', arguments); }

A

Admin • 833.24K Points
Coach

Q. Consider the following code snippet :

Code:
var string2Number=parseInt("456pqr");
  • (A) 456pqr
  • (B) Exception
  • (C) NaN
  • (D) 456

A

Admin • 833.24K Points
Coach

Q. Consider the following code snippet : will this code work?

Code:
var tensquared = (function(n) {return n*n;}(100));
  • (A) Exception will be thrown
  • (B) Memory leak
  • (C) Error
  • (D) Yes

A

Admin • 833.24K Points
Coach

Q. Do functions in JavaScript necessarily return a value?

  • (A) some functions do not return any value
  • (B) It is mandatory
  • (C) Not necessary
  • (D) Few functions return values by default

A

Admin • 833.24K Points
Coach

Q. Consider the following code snippet :

Code:
var Total=eval("5*5+10");
  • (A) 35 as an integer value
  • (B) 35 as a string
  • (C) Exception is thrown
  • (D) 5*5+10

A

Admin • 833.24K Points
Coach

Q. Consider the following code snippet.
Which is an equivalent code for the above code snippet?

Code:
opt.fun(p,q);
  • (A) opt.fun(p && q);
  • (B) opt(fun)["p","q"];
  • (C) opt.fun(p) && opt.fun(q);
  • (D) opt["fun"](p,q);

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