arunram.krish
Quiz by , created more than 1 year ago

Quiz on Object Oriented Javascript

5890
3
0
arunram.krish
Created by arunram.krish over 8 years ago
Close

Quiz - Object Oriented Javascript

Question 1 of 15

1

What are the different ways in which you can create a javascript object? Choose ALL the right options

Select one or more of the following:

  • var object = { prop1: "value1", prop2 : "value2"};

  • var object = new Object();

  • var object = {};

  • var object = Object.create({});

Explanation

Question 2 of 15

1

How to create a constructor function?

Select one of the following:

  • 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

Explanation

Question 3 of 15

1

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.

Select one of the following:

  • 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);

Explanation

Question 4 of 15

1

When does a Closure scope gets created?

Select one of the following:

  • 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

Explanation

Question 5 of 15

1

How can I create a constant in Javascript 5?

Select one of the following:

  • const myConstant = 3.414;

  • var myConstant = { value : "3.414";}

  • var myConstant = new Object(3.414)

  • var myConstant = Object.create(null, { value: {
    configurable : false,
    writable : false,
    enumerable : false,
    value : 3.414
    }
    });

Explanation

Question 6 of 15

1

How does Javascript achieve Inheritance?

Select one of the following:

  • Inheritance using extends keyword

  • Inheritance through Constructor chaining

  • Inheritance through Prototype chaining

  • Inheritance achieved programmatically

Explanation

Question 7 of 15

1

Javascript does not support overriding?

Select one of the following:

  • True
  • False

Explanation

Question 8 of 15

1

It is a better practice (in terms of performance) to create deep inheritance and access methods in the ancestor classes.

Select one of the following:

  • True
  • False

Explanation

Question 9 of 15

1

It is possible to create namespaces in Javascript.

Select one of the following:

  • True
  • False

Explanation

Question 10 of 15

1

It is possible to implement Singleton pattern in javascript.

Select one of the following:

  • True
  • False

Explanation

Question 11 of 15

1

Every Javascript function is an object with the constructor as "Function"

Select one of the following:

  • True
  • False

Explanation

Question 12 of 15

1

How can I create immutable property in a javascript object?

Select one of the following:

  • Using closure

  • Using JSON

  • Using Object.defineProperty and specify only get and no set function

  • By making the property private

Explanation

Question 13 of 15

1

How to ensure that a property in Javscript object is never removed or re-configured

Select one of the following:

  • Define the property with private modifier

  • It is not possible to stop removing the property from object

  • Every property defined using "Object.defineProperty" cannot be removed

  • Using Object.defineProperty and setting "configurable" to false

Explanation

Question 14 of 15

1

How can I avoid creating global variables and functions used most often for initialization?

Select one of the following:

  • Using temporary inner / anonymous function functions

  • Using just closure

  • Using constructor

  • Using window object

Explanation

Question 15 of 15

1

How can I create Block - scoped variable in ES-6?

Select one of the following:

  • Using var

  • Using let

  • Using const

  • Using def

Explanation