1. Assume current datetime is “Wed Jun 22 2016 12:00:00 GMT+0530 (IST)”. And we have the following code, what will be the output for below code?

      
        var a = [], count = 0, max = 3;

         function runTime() {
          setTimeout(function() {
           a.push(new Date());
           if (count++ < max)
            runTime();
          }, 1000);
         }
         function getDatearray() {
           runTime();
           return a;
         }
         console.log(getDatearray());
      
    

  1. ["Wed Jun 22 2016 12:00:00 GMT+0530 (IST)", "Wed Jun 22 2016 12:00:01 GMT+0530 (IST)", "Wed Jun 22 2016 12:00:02 GMT+0530 (IST)"]
  2. ["Wed Jun 22 2016 12:00:00 GMT+0530 (IST)", "Wed Jun 22 2016 12:00:01 GMT+0530 (IST)"]
  3. ["Wed Jun 22 2016 12:00:00 GMT+0530 (IST)", "Wed Jun 22 2016 12:00:00 GMT+0530 (IST)"]
  4. ["Wed Jun 22 2016 12:00:00 GMT+0530 (IST)"]
  5. []
  6. ["Wed Jun 22 2016 12:00:00 GMT+0530 (IST)", null]
  7. [null, "Wed Jun 22 2016 12:00:00 GMT+0530 (IST)"]
  8. error
  9. none of the above

Ans: f

2. Output for the below code

      
        var obj = [{itemno: 1, itemname: 'Angular'}, {itemno: 2, itemname: 'Node'}, {itemno: 3, itemname: 'Backbone'}];

        function format(ob) {
          ob[2].itemname = 'React';
        }
        format(obj);
        console.log(JSON.stringify(obj));

      
    

  1. [{"itemno":1,"itemname":"Angular"},{"itemno":2,"itemname":"Node"},{"itemno":3,"itemname":"React"}]
  2. [{"itemno":1,"itemname":"Angular"},{"itemno":2,"itemname":"Node"},{"itemno":3,"itemname":"Backbone"}]
  3. error
  4. []
  5. null
  6. [{itemno: 1, itemname: 'Angular'}, {itemno: 2, itemname: 'Node'}, null]
  7. [null, null]
  8. ["cannot convert", "cannot convert", "cannot convert"]
  9. none of the above

Ans: f

3. Output for the following code

      
         var a = -12;

           if (a -= a+a)
            console.log(a);
           else
            console.log('Hey, No');
           
    

  1. Hey, No
  2. -12
  3. error
  4. 0
  5. 12
  6. -24
  7. 24
  8. -12 12
  9. 12 -12
  10. none of the above

Ans: e

4. Output for the following code

      
        function constfuncs()
        {
          var funcs = [];
          for(var i = 0; i < 23; i++)
          funcs[i] = function() { return i; };
          return funcs;
        }
        var funcs = constfuncs();
        console.log(funcs[5]());
      
    

  1. 9
  2. 23
  3. 10
  4. 5
  5. 2
  6. 20
  7. 22
  8. cannot predict
  9. error
  10. none of the above

Ans: b

4. Output for the following code

      
         function x() {
            console.log("2"+5+8);
          }
          x();
      
    

  1. 258
  2. c
  3. 7
  4. 78
  5. 213
  6. 2513
  7. 13
  8. 58
  9. none of the above

Ans: a

5. Predict the output.

      
         var count=0; 
          setTimeout(fun,1000);

          function fun(){

            console.log(count)

            if(count!==5)
            setTimeout(fun,1000);   

            count++;
          }
       
    

  1. program will print 0,1,2,3,4,6,7...till infinite
  2. program will print 0,1,2,3,4,5...till infinite
  3. program will print 0,1,2,3,4
  4. Error
  5. program will print 0,1,2,3,4,5
  6. None of these.

Ans: c

6. What will be output for below code.

      
         if (null == undefined) {
           console.log(‘Equal’);
          } else {
           console.log(‘Not equal’);
          }

       
    

  1. Equal
  2. Not equal
  3. Error
  4. None of these.

Ans: a

7. What will be output for below code.

      
         if (null == undefined) {
           console.log(‘Equal’);
          } else {
           console.log(‘Not equal’);
          }

       
    

  1. Equal
  2. Not equal
  3. Error
  4. None of these.

Ans: a

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.