What are the different ways in which you can create a javascript object? Choose ALL the right options
Responda
var object = { prop1: "value1", prop2 : "value2"};
var object = new Object();
var object = {};
var object = Object.create({});
Questão 2
Questão
How to create a constructor function?
Responda
Any function when prefixed with "new" keyword at the time of invocation acts like a constructor function.
Name of the function should be "constructor"
You have to assign a property named "constructor" and assign a function to it
Constructor function cannot be created in javascript
Questão 3
Questão
How do you demonstrate inheritance in Javascript? Consider "BaseClass" is the name of the parent class and "SubClass" is the name of the sub-class.
Responda
class SubClass extends BaseClass { }
function SubClass() {
BaseClass.apply(this, Array.prototype.slice.call(arguments, 0);
}
SubClass.prototype = Object.create(BaseClass.prototype);
function SubClass() {
BaseClass.apply(this, Array.prototype.slice.call(arguments, 0);
}
function SubClass() {
super(Array.prototype.slice.call(arguments, 0));
}
SubClass.prototype = Object.create(BaseClass.prototype);
Questão 4
Questão
When does a Closure scope gets created?
Responda
Every function has a Closure scope associated with it
Every time a inner function is defined within another function
When an inner function is defined within another function and that refers to variables that are available at the defining function (local variables of enclosing functions and its parent right until global)
A closure keyword is available. When a variable is declared with that modifier, closure scope is created