Week 10 Quiz

What is the difference between a library and a framework?
Examine the following code and explain to me what is going on?

What Will Print?

Consider the following code:

(function() {
   var a = b = 5;
})();

console.log(b);

What will be printed on the console?
What will it print if you were in "strict" mode?

Write a Native method:

Define a repeatify function on the String object/class. The function accepts an integer that specifies how many times the string has to be repeated. The function returns the string repeated the number of times specified. For example:

console.log('hello'.repeatify(3));
Should print hellohellohello.

Hoisting:

What’s the result of executing this code and why?

function test() {
   console.log(a);
   console.log(foo());
   
   var a = 1;
   function foo() {
      return 2;
   }
}

test();
The problem with this:

What is the result of the following code? Explain your answer.

var fullname = 'John Doe';
var obj = {
   fullname: 'Colin Ihrig',
   prop: {
      fullname: 'Aurelio De Rosa',
      getFullname: function() {
         return this.fullname;
      }
   }
};

console.log(obj.prop.getFullname());

var test = obj.prop.getFullname;

console.log(test());
Object Type:

What is a potential pitfall with using typeof bar === "object" to determine if bar is an object? How can this pitfall be avoided?

Same thing?

...This is tricky...

Consider the two functions below. Will they both return the same thing? Why or why not?

function foo1()
{
  return {
      bar: "hello"
  };
}

function foo2()
{
  return
  {
      bar: "hello"
  };
}