
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
(Full Stack JavaScript) Object & Object Obstructors Knowledge Assessment Q & S 2024(Full Stack JavaScript) Object & Object Obstructors Knowledge Assessment Q & S 2024(Full Stack JavaScript) Object & Object Obstructors Knowledge Assessment Q & S 2024(Full Stack JavaScript) Object & Object Obstructors Knowledge Assessment Q & S 2024
Typology: Exams
1 / 24
This page cannot be seen from the preview
Don't miss anything!

















class b. instance c. new d. objectnewRationale: The new keyword is used to create a new instance of an object using a constructor function.
function Person(name) { this.name = name; } const person1 = new Person("Alice"); console.log(person1 instanceof Person); a. true b. falseAn object from which other objects inherit propertiesRationale: In JavaScript, prototypes allow objects to inherit properties and methods from other objects.
function Car(make, model) { this.make = make; this.model = model; } Car.prototype.getDetails = function() { return this.make + " " + this.model; } const myCar = new Car("Toyota", "Corolla"); console.log(myCar.getDetails()); a. undefined undefined b. Toyota Corolla c. Toyota undefined d. ErrorToyota CorollaRationale: The method getDetails in the prototype correctly returns the make and model of the car.
prototypeRationale: The prototype property lets you add methods and properties to all instances of a function or object.
instantiationRationale: Instantiation is the process of creating an instance of an object from a class or constructor function.
Rationale: Methods on a prototype are shared among all instances created from the constructor.
Rationale: Objects can also be created using object literals, Object.create(), and class syntax.
Rationale: JavaScript only supports single inheritance through prototypes. However, mixins can be used to achieve multiple inheritance- like behavior.
Object.create() method allows you to specify the prototype of a new object.Rationale: Object.create() creates a new object with the specified prototype object.
Rationale: If a constructor function explicitly returns an object, this object will be the result of the new expression, overriding the default object.
private keyword d. Both a and bRationale: Private properties can be simulated using closures (a), and by convention, an underscore (b) indicates private properties (though this is not enforced by the language).
constructor(height, width){ } calcArea() { return this.height this.width; } }
## Answer: a. Rationale: The ES6 class syntax is correctly used in option (a), where the constructor is defined properly, and the method `calcArea` is outside the constructor. 18. What will be the output of the following code? ```javascript class Animal { constructor(name) { this.name = name; } speak() { console.log(`${this.name} makes a noise`); } } class Dog extends Animal { speak() { console.log(`${this.name} barks`); } } const d = new Dog('Mitzie'); d.speak(); a. Mitzie makes a noise b. Mitzie barks c. Error d. undefined barks
Mitzie barksRationale: The Dog class overrides the speak method of the Animal class, so barks is printed instead of makes a noise.
in b. hasOwnPropertyd) To execute a function
Rationale: Constructor functions are a fundamental concept in JavaScript used to create multiple instances of an object, each with their own unique properties.
Rationale: In a constructor function, the 'this' keyword refers to the instance of the object that is being created, not the global object.
Rationale: The proto property is a reference to the prototype of the object from which properties and methods are inherited.
Rationale: The new keyword is used before a constructor function, not a string, to create an instance of an object.
Rationale: Local variables within a constructor function are private to that function and cannot be accessed outside of it.
Rationale: Adding a method to the constructor's prototype property ensures that all instances of the object inherit the method.
Rationale: The 'new' keyword is used in JavaScript to create an instance of an object from a constructor function.
Rationale: Properties can be added to JavaScript objects at any time, even after they have been created.
Rationale: Constructor functions are used to initialize new objects with specific properties and methods.
Rationale: In JavaScript, a constructor function is defined using the 'function' keyword.
Rationale: The constructor property of an object points to the function that created that particular object.
Rationale: The constructor/prototype pattern was commonly used to simulate class-like behavior in JavaScript before the introduction of the class syntax in ES6. a. Which of the following statements about object-oriented programming is true? i. Objects are instances of classes. ii. Objects do not have properties or methods. iii. Objects cannot be passed as arguments to functions. iv. Objects cannot be modified once created.
Rationale: Understanding the relationship between objects and classes is fundamental to object-oriented programming. Objects are instances of classes, inheriting their properties and methods. Fill-in-the-Blank Classes are templates for creating objects. They define the initial state and behavior that objects created from them will have.
Rationale: The 'new' keyword is used to create a new instance of a constructor function, allowing for the creation of multiple objects with shared properties and methods. Fill-in-the-Blank An object constructor in JavaScript is a function that is used to create multiple instances of an object with the same structure.
Rationale: Object constructors provide a convenient way to create multiple objects with consistent properties and methods, promoting code reusability. True/False In JavaScript, every object has a prototype property that allows for inheritance of properties and methods.
Rationale: The prototype property in JavaScript enables objects to inherit properties and methods from other objects, facilitating the concept of inheritance in object-oriented programming. Multiple Choice
c. Which of the following methods is used to create a new object with a specified prototype object in JavaScript? i. Object.create() ii. Object.defineProperties() iii. Object.freeze() iv. Object.keys()
Rationale: The Object.create() method in JavaScript is used to create a new object with a specified prototype object, allowing for prototype-based inheritance. Fill-in-the-Blank The prototype property of an object in JavaScript is used to enable object inheritance.
Rationale: The prototype property establishes a chain of inheritance in JavaScript, allowing objects to inherit properties and methods from prototype objects. True/False