JavaScript MCQs with answers Page - 14

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. Which one of the following code is equivalent to call a function "x" of the class "a" which have two arguments g and h?

  • (A) a,x(g,h);
  • (B) x(g) &&a.x(g);
  • (C) x(a,g);
  • (D) (g,h);

A

Admin • 833K Points
Coach

Q. Which one of the following code is equivalent to the following given code?

Code:
a.x(g,h);  
  • (A) x (g) &&a.x (h);
  • (B) a [ "x" ] ( g , h );
  • (C) a (x )[ "g" , "h" ];
  • (D) x( g&&h );

A

Admin • 833K Points
Coach

Q. Which one of the following options is the correct output for the given code of JavaScript?

Code:
functionfun()  
{  
var a=1;  
var b=2;  
return a*b;  
}  
document.write(fun());  
  • (A) 2
  • (B) 3
  • (C) 0
  • (D) Error

A

Admin • 833K Points
Coach

Q. Which one of the following options is the correct output for the given code of JavaScript?

Code:
var arr=[1, 3, 5, 8 ,11];  
var value =Math.max.apply(null,arr);  
document.writeln(value);  
  • (A) 7
  • (B) 11
  • (C) 3
  • (D) 9

A

Admin • 833K Points
Coach

Q. Which one of the following options is the correct output for the given code of JavaScript?

Code:
var person =  
{  
      name: "James",  
getName:function()  
{  
nreturnthis.name;  
}  
}  
varunboundName=person.getName;  
varboundName=unboundName.bind(person);  
document.writeln(boundName());  
  • (A) James
  • (B) compilation error
  • (C) runtime error
  • (D) undefined

A

Admin • 833K Points
Coach

Q. Which one of the following options is the correct output for the given code of JavaScript?

Code:
function code(id,name)  
{  
        this.id= id;  
        this.name= name;  
}  
functionpcode(id,name)  
{  
        code.call(this,id,name);  
}  
document.writeln(newpcode(004,"James Deo").id);
  • (A) James Deo
  • (B) compilation error
  • (C) runtime error
  • (D) undefined

A

Admin • 833K Points
Coach

Q. Which one of the following options is the correct output for the given code of JavaScript?

Code:
var pow=newFunction("num1","num2","return Math.pow(num1,num2)");  
document.writeln(pow(2,3));  
  • (A) 8
  • (B) 3
  • (C) 6
  • (D) Error

A

Admin • 833K Points
Coach

Q. Which one of the following keywords is used for defining the function in the JavaScript?

  • (A) Void
  • (B) init
  • (C) main
  • (D) function

A

Admin • 833K Points
Coach

Q. In JavaScript, do the functions always return a value?

  • (A) Yes, functions always returns a value
  • (B) No, it is not necessary
  • (C) A number of functions return values by default
  • (D) some functions do not return any value

A

Admin • 833K Points
Coach

Q. Which one of the following codes is correct for concatenating the strings passed into the function?

  • (A) functionconcatenate() { returnString.prototype.concat(', arguments); }
  • (B) functionconcatenate() { returnString.prototype.concat.apply(', arguments); }
  • (C) functionconcatenate() { returnString.prototype.apply(', arguments); }
  • (D) functionconcatenate() { returnString.concat.apply(', arguments); }