Skip to content

Instantly share code, notes, and snippets.

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

#Quiz:

  1. What’s the result of:

     function A() {}
     A.prototype.name = 'A';
    
     var a = new A();
     var b = new A();
    
     a.name = 'B';
    
     console.log(a.name, b.name);
    

    Answers:

    • 'A', 'A'
    • 'B', 'A'
    • 'B', 'B'
  2. What’s the result of:

     function A() {}
     A.prototype = {
         name: 'A';
     };
    
     var a = new A();
    
     A.prototype = {
         name: 'B'
     };
    
     var b = new A();
    
     console.log(a.name, b.name);
    

    Answers:

    • 'A', 'A'
    • 'A', 'B'
    • 'B', 'B'
  3. What’s the result of and why:

     var car = {
         color: 'red',
         getColor: function() {
             alert(this.color);
         }
     };
    
     car.getColor();
     var getColor = car.getColor;
     getColor();
    
  4. What’s the result of:

     function A() {
         return 5;
     }
    
     var a = new A();
    
     console.log(a);
    

    Answers:

    • 5
    • Object
    • undefined
    • body of function
  5. What’s the result of:

     function A() {
         this.name = 'A';
     }
    
     var a = A();
    
     console.log(a.name)
    

    Answers:

    • 'A'
    • TypeError
    • Window
    • depends on browser
  6. What’s the result of:

     function A() {}
     A.prototype = 5;
    
     var a = new A()
    
     console.log(Object.getPrototypeOf(a));
    

    Answers:

    • 'object'
    • 5
    • 'undefined'
    • Error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment