#Quiz:
-
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'
-
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'
-
What’s the result of and why:
var car = { color: 'red', getColor: function() { alert(this.color); } }; car.getColor(); var getColor = car.getColor; getColor();
-
What’s the result of:
function A() { return 5; } var a = new A(); console.log(a);
Answers:
- 5
- Object
- undefined
- body of function
-
What’s the result of:
function A() { this.name = 'A'; } var a = A(); console.log(a.name)
Answers:
- 'A'
- TypeError
- Window
- depends on browser
-
What’s the result of:
function A() {} A.prototype = 5; var a = new A() console.log(Object.getPrototypeOf(a));
Answers:
- 'object'
- 5
- 'undefined'
- Error