JavaScript Questions & Answers – Functions and Functional Programming | JavaScript MCQs
Questions
1
What will be the output of the following JavaScript statement?
var grand_Total=eval("10*10+5");
Answer: 105 as an integer value
2
Do functions in JavaScript necessarily return a value?
Answer: Few functions return values by default
⭐ Make GKSeries Your Preferred Source on Google
Add GKSeries as Preferred Source
3
Will the following JavaScript code work?
var tensquared = (function(x) {return x*x;}(10));
Answer: Yes, perfectly
4
What will be the output of the following JavaScript code?
var string2Num=parseInt("123xyz");
Answer: 123
5
The one-liner code that concatenates all strings passed into a function is ____________
Answer: function concatenate()
{
return String.prototype.concat.apply('', arguments);
}
6
If you have a function f and an object o, you can define a method named m of o with ________
Answer: o.m=f;
7
What will be the equivalent statement of the following JavaScript statement?
var o = new Object();
Answer: var o= new Object;
8
What is the difference between the two lines in the following JavaScript code?
!!(obj1 && obj2);
(obj1 && obj2);
Answer: The first line results in a real boolean value whereas the second line merely checks for the existence of the objects
9
What will be the state stored in d in the following JavaScript code?
var c = counter(), d = counter(); c.count() d.count() c.reset() c.count() d.count()
Answer: 1
10
What will be the last statement return in the following JavaScript code?
function constfuncs()
{
var funcs = [];
for(var i = 0; i < 10; i++)
funcs[i] = function() { return i; };
return funcs;
}
var funcs = constfuncs();
funcs[5]()
Answer: 10
11
What will be the output of the following JavaScript code?
var arr = [7, 5, 9, 1]; var min = Math.min.apply(null, arr); document.writeln(min);
Answer: 1
12
What will be the output of the following JavaScript code?
var add=new Function("num1","num2","return num1+num2");
document.writeln(add(2,5));
Answer: 7
13
What will be the output of the following JavaScript code?
var a=3.7; var b=2; a=ciel(a) document.writeIn(a*b);
Answer: 8
14
What will be the output of the following JavaScript code?
var a=2.99; var ans=floor(a)*floor(a) console.log(ans);
Answer: 4
15
What will be the output of the following JavaScript code?
var a=225; document.writeln(Math.sqrt(a));
Answer: 15