Skip to content

Instantly share code, notes, and snippets.

@oleksiilevzhynskyi
Created July 8, 2013 11:24
Show Gist options
  • Save oleksiilevzhynskyi/5947999 to your computer and use it in GitHub Desktop.
Save oleksiilevzhynskyi/5947999 to your computer and use it in GitHub Desktop.

#Quiz:

  1. What’s the result of:

     console.log(f());
     function f() {
         return 1;
     }
    

    Answers:

    • null
    • undefined
    • 1
    • error
  2. How do these differ?

     function foo() {}
     // versus
     var foo = function() {};
    
  3. What’s the result of:

     function f() {
         var a = 5;
         return new Function('b', 'return a + b');
     }
     consoe.log( f()(1) );
    

    Answers:

    • 1
    • 6
    • undefined
    • NaN
    • error
  4. What’s the result of:

     var f = function(x) {
         console.log(x)
     }
    
     (function() {
         f(1);
     }())
    

    Answers:

    • nothing
    • 1
    • error
    • depends on browser
  5. What’s the result of:

     function() {
         if (true) {
             var a = 5;
         }
         console.log(a);
     }
    

    Answers:

    • nothing
    • 5
    • error
    • depends on browser
  6. What’s the result of:

     function f(x, y) {
         x = 10;
         console.log(
             arguments[0],
             arguments[1]
         );
     }
    
     f();
    

    Answers:

    • 10, null
    • 10, undefined
    • undefined, undefined
    • 10, NaN
  7. What’s the result of:

     function a(x) {
         return x * 2;
     }
     var a;
     console.log(a);
    

    Answers:

    • error
    • 2
    • undefined
    • body of function
  8. What’s the result of:

     (function f() {
         function f() { return 1; }
         return f();
         function f() { return 2; }
     })();
    

    Answers:

    • 1
    • 2
    • undefined
    • depends on browser
  9. What’s the result of:

     (function() {
         return typeof arguments;
     })();
    

    Answers:

    • 'object'
    • 'array'
    • 'arguments'
    • 'undefined'
  10. What’s the result of:

    var f = function g() { return 'test'; };
    console.log( typeof g() );
    

    Answers:

    • string
    • undefined
    • function
    • error
  11. What’s the result of:

    (function() {
        var kittySays = 'Meow';
    })();
    console.log(kittySays);
    

    Answers:

    • 'Meow'
    • undefined
    • null
    • error
  12. What’s the result of:

    console.log (f());
    var f = function () { return 1; };
    

    Answers:

    • null
    • undefined
    • 1
    • error
  13. What’s the result of:

    var x = 1;
    
    (function() {
        console.log(x);
        return x;
        var x = 2;
    })();
    

    Answers:

    • 2
    • undefined
    • 1
    • error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment