GkSeries.com

JavaScript Questions & Answers – Functions and Functional Programming | JavaScript MCQs

(1) What will be the output of the following JavaScript statement?

var grand_Total=eval("10*10+5");

[A] 10*10+5
[B] 105 as a string
[C] 105 as an integer value
[D] Exception is thrown
Answer: 105 as an integer value
(2) Do functions in JavaScript necessarily return a value?
[A] It is mandatory
[B] Not necessary
[C] Few functions return values by default
[D] some functions do not return any value
Answer: Few functions return values by default

DOWNLOAD CURRENT AFFAIRS PDF FROM APP

(3) Will the following JavaScript code work?

var tensquared = (function(x) {return x*x;}(10));

[A] Yes, perfectly
[B] Error
[C] Exception will be thrown
[D] Memory leak
Answer: Yes, perfectly
(4) What will be the output of the following JavaScript code?

var string2Num=parseInt("123xyz");

[A] 123
[B] 123xyz
[C] Exception
[D] NaN
Answer: 123
(5) The one-liner code that concatenates all strings passed into a function is ____________
[A]
function concatenate()
   {
       return String.prototype.concat('', arguments);
   }
[B]
 function concatenate()
 {
       return String.prototype.apply('', arguments);
  }
[C]
function concatenate()
  {
       return String.concat.apply('', arguments);
  }
[D]
function concatenate()
  {
      return String.prototype.concat.apply('', arguments);
   }
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 ________
[A] o.m=m.f;
[B] o.m=f;
[C] o=f.m;
[D] o=f;
Answer: o.m=f;
(7) What will be the equivalent statement of the following JavaScript statement?

var o = new Object();

[A] var o = Object();
[B] var o;
[C] var o= new Object;
[D] Object 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);

[A] Both the lines result in a boolean value “True”
[B] Both the lines result in a boolean value “False”
[C] Both the lines check just for the existence of the object alone
[D] The first line results in a real boolean value whereas the second line merely checks for the existence of the objects
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()
[A] 1
[B] 0
[C] Null
[D] Undefined
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]()
[A] 9
[B] 0
[C] 10
[D] 12
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);
[A] 7
[B] 5
[C] 1
[D] 9
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));
[A] 2
[B] 5
[C] Error
[D] 7
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);
[A] 6
[B] 7.4
[C] 7.5
[D] 8
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);
[A] 9
[B] 8.31
[C] Error
[D] 4
Answer: 4
(15) What will be the output of the following JavaScript code?
var a=225;
document.writeln(Math.sqrt(a));
[A] 225
[B] 15
[C] Error
[D] Undefined
Answer: 15

Please share this page

Click Here to Read more questions

Teacher Eligibility Test