110). 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
Show Answer
Correct Answer: Return type, Function keyword, Identifier and Parentheses
Notes:
Answer: c
Explanation: The function definitions begin with the keyword function followed by an identifier that names the function and a pair of parentheses around a comma-separated list of zero or more identifiers.
111). 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
Show Answer
Correct Answer: Returns undefined
Notes:
Answer: b
Explanation: The above code snippet returns undefined.
112). When does the function name become optional in JavaScript?
function printprops(o)
{
for(var p in o)
console.log(p + ": " + o[p] + "\n");
}
[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
Show Answer
Correct Answer: When the function is defined as expressions
Notes:
Answer: b
Explanation: The function name is optional for functions defined as expressions. A function declaration statement actually declares a variable and assigns a function object to it.
113). What is the purpose of a return statement in a function?
function printprops(o)
{
for(var p in o)
console.log(p + ": " + o[p] + "\n");
}
[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
Show Answer
Correct Answer: Stops executing the function and returns the value
Notes:
Answer: d
Explanation: The return stops the execution of the function when it is encountered within the function. It returns the value to the statement where the function is called.
114). What will happen if a return statement does not have an associated expression?
function printprops(o)
{
for(var p in o)
console.log(p + ": " + o[p] + "\n");
}
[A]It returns the value 0
[B]It will throw an exception
[C] It returns the undefined value
[D] It will throw an error
Show Answer
Correct Answer: It returns the undefined value
Notes:
Answer: c
Explanation: A function without a return statement will return a default value. If the return statement does not have an associated expression then it returns an undefined value.
115). A function with no return value is called ___________
function printprops(o)
{
for(var p in o)
console.log(p + ": " + o[p] + "\n");
}
[A]Procedures
[B]Method
[C]Static function
[D]Dynamic function
Show Answer
Correct Answer: Procedures
Notes:
Answer: a
Explanation: Void functions does not return a value. Functions with no return value are sometimes called procedures.
116). The function stops its execution when it encounters?
function printprops(o)
{
for(var p in o)
console.log(p + ": " + o[p] + "\n");
}
[A]continue statement
[B]break statement
[C]goto statement
[D]return statement
Show Answer
Correct Answer: return statement
Notes:
Answer: d
Explanation: Continue statement and break statement are used in the loops for skipping the iteration or going out of the loop. Whenever a return statement is encountered the function execution is stopped.
117). Which keyword is used to define the function in javascript?
function printprops(o)
{
for(var p in o)
console.log(p + ": " + o[p] + "\n");
}
[A]void
[B]int
[C]function
[D]main
Show Answer
Correct Answer: function
Notes:
Answer: c
Explanation: A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses(). Function names can contain letters, digits, underscores, and dollar signs (same rules as variables).
118). Which is an equivalent code to invoke a function m of class o that expects two arguments x and y?
function printprops(o)
{
for(var p in o)
console.log(p + ": " + o[p] + "\n");
}
[A]o(x,y);
[B]o.m(x) && o.m(y);
[C] m(x,y);
[D]o.m(x,y);
Show Answer
Correct Answer: o.m(x,y);
Notes:
Answer: d
Explanation: The two argument in a function are separated by a comma (,). The code above is an invocation expression: it includes a function expression o.m and two argument expressions, x and y.
119). 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);
Show Answer
Correct Answer: o[“m”](x,y);
Notes:
Answer: b
Explanation: Another way to write o.m(x,y) is o[“m”](x,y).o[“m”] will access the property of the object and parenthesis will access the function present inside it.
120). What will be the output of the following JavaScript code?
function info()
{
int a=1;
int b=2;
return a*b;
}
document.write(info());
Show Answer
Correct Answer: 2
Notes:
Answer: b
Explanation: document.write() is used to write the output on the console. In the above code document.write() passes a function as its argument and the function returns 2 which is printed as output.
121). 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);
Show Answer
Correct Answer: 9
Notes:
Answer: d
Explanation: apply() is a predefined function method in javascript. The argument of apply() method contains elements of an array. It contains two values as argument which are optional as input.
122). 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
Show Answer
Correct Answer: Rahul
Notes:
Answer: c
Explanation: The javascript bind() function is used to create a new function. The newly created function has its own set of keywords.
123). 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
Show Answer
Correct Answer: 101
Notes:
Answer: b
Explanation: The JavaScript call() method is used to call a function containing “this” value as an argument. It returns the result of calling function.
124). 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));
Show Answer
Correct Answer: 8
Notes:
Answer: c
Explanation: pow function is a predefined function which is present in the math library of javascript. The pow function accepts two arguments of which power of the first argument is calculated with respect to the second.