JavaScript From Beginner To Advanced

0% completed

Previous
Next
Quiz
What is the primary purpose of a prototype in JavaScript?
Choose all correct options
To provide a mechanism for inheritance
To allocate memory for new objects
To store default configurations for objects
To increase performance by sharing methods among instances
Which statement is true regarding constructor functions in JavaScript?
A
Constructor functions are automatically generated for every object.
B
Constructor functions are special methods used to initialize newly created objects.
C
Constructor functions can only be called on existing objects.
D
Constructor functions must return a value.
Which of the following is NOT a feature of classes in JavaScript?
A
Static methods
B
Public fields
C
Multiple inheritance
D
Encapsulation
What does the following JavaScript code demonstrate?
class Person {
    constructor(name) {
        this._name = name;
    }
    get name() {
        return this._name;
    }
    set name(value) {
        this._name = value;
    }
}
let person = new Person("Jane");
console.log(person.name);
person.name = "Doe";
console.log(person.name);
A
Method Overloading
B
Data Encapsulation using accessors
C
Polymorphism
D
Public method declaration
Encapsulation in JavaScript is best achieved through which of the following?
A
Using global variables
B
Using closures to protect private data
C
Placing all code in a single function
D
Using the 'public' keyword
What is the output of the following JavaScript code involving classical inheritance?
class Animal {
    constructor(name) {
        this.name = name;
    }
    speak() {
        return this.name + ' makes a noise.';
    }
}

class Dog extends Animal {
    speak() {
        return this.name + ' barks.';
    }
}

let pet = new Dog("Rover");
console.log(pet.speak());
A
Rover makes a noise.
B
Rover barks.
C
undefined barks.
D
Error
Which of the following is an accurate representation of abstraction in JavaScript?
A
Making all properties and methods public.
B
Using class syntax to encapsulate and selectively expose class internals.
C
Directly modifying object properties without using methods.
D
Implementing every method directly within the constructor.
How does polymorphism manifest in JavaScript?
A
Through functions accepting different data types.
B
By allowing methods in derived classes to override methods in their base classes.
C
Through the use of single inheritance only.
D
By ensuring all objects use the same methods.
Which option correctly demonstrates the destructuring assignment used for object properties?
A
let {x, y} = {x: 1, y: 2};
B
let [x, y] = {x: 1, y: 2};
C
let {x: 1, y: 2} = obj;
D
let [x: xVal, y: yVal] = {x: 1, y: 2};

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next