GkSeries.com

JavaScript Questions & Answers – Defining and Invoking Functions | JavaScript MCQs

(1) The function definitions in JavaScript begins with _____________
[A] Identifier and Parentheses
[B] Return type and Identifier
[C] Return type, Function keyword, Identifier and Parentheses
[D] Identifier and Return type
Answer: Return type, Function keyword, Identifier and Parentheses
(2) What will be the output of the following JavaScript code?
function printprops(o)
	{
    for(var p in o)
     	console.log(p + ": " + o[p] + "\n");
	}
[A] Prints the contents of each property of o
[B] Returns undefined
[C] Prints only one property
[D] Prints the address of elements
Answer: Returns undefined

DOWNLOAD CURRENT AFFAIRS PDF FROM APP

(3) When does the function name become optional in JavaScript?
[A] When the function is defined as a looping statement
[B] When the function is defined as expressions
[C] When the function is predefined
[D] when the function is called
Answer: When the function is defined as expressions
(4) What is the purpose of a return statement in a function?
[A] Returns the value and continues executing rest of the statements, if any
[B] Returns the value and stops the program
[C] Returns the value and stops executing the function
[D] Stops executing the function and returns the value
Answer: Stops executing the function and returns the value
(5) What will happen if a return statement does not have an associated expression?
[A] It returns the value 0
[B] It will throw an exception
[C] It returns the undefined value
[D] It will throw an error
Answer: It returns the undefined value
(6) A function with no return value is called ___________
[A] Procedures
[B] Method
[C] Static function
[D] Dynamic function
Answer: Procedures
(7) The function stops its execution when it encounters?
[A] continue statement
[B] break statement
[C] goto statement
[D] return statement
Answer: return statement
(8) Which keyword is used to define the function in javascript?
[A] void
[B] int
[C] function
[D] main
Answer: function
(9) Which is an equivalent code to invoke a function m of class o that expects two arguments x and y?
[A] o(x,y);
[B] o.m(x) && o.m(y);
[C] m(x,y);
[D] o.m(x,y);
Answer: o.m(x,y);
(10) What will be the equivalent code of the following JavaScript code?

o.m(x,y);

[A] o.m(x) && o.m(y);
[B] o[“m”](x,y);
[C] o(m)[“x”,”y”];
[D] o.m(x && y);
Answer: o[“m”](x,y);
(11) What will be the output of the following JavaScript code?
function info()
	{ 
    int a=1;
   int b=2;
    return a*b;
	}  
document.write(info());
[A] 1
[B] 2
[C] 3
[D] error
Answer: 2
(12) What will be the output of the following JavaScript code?
var arr = [7, 5, 9, 1]; 
var value = Math.max.apply(null, arr);
document.writeln(value);
[A] 7
[B] 5
[C] 1
[D] 9
Answer: 9
(13) What will be the output of the following JavaScript code?
var person =
{ 
      name: “Rahul”,
      getName: function()
      {  
         nreturn this.name; 
      }  
}
var unboundName = person.getName;  
var boundName = unboundName.bind(person);
document.writeln(boundName());
[A] runtime error;
[B] compilation error
[C] Rahul
[D] undefined
Answer: Rahul
(14) What will be the output of the following JavaScript code?
function code(id,name)
{
  		this.id = id;
  		this.name = name;
}
function pcode(id,name)
{
 		code.call(this,id,name);
}
document.writeln(new pcode(101,"vivek").id);
[A] vivek
[B] 101
[C] Runtime error
[D] Compilation error
Answer: 101
(15) What will be the output of the following JavaScript code?
var pow=new Function("num1","num2","return Math.pow(num1,num2)");
     document.writeln(pow(2,3));
[A] 2
[B] 3
[C] 8
[D] error
Answer: 8

Please share this page

Click Here to Read more questions

Teacher Eligibility Test