The concept of creating a single function or method that can operate on multiple types of objects is known as _________.

  • Overloading
  • Inheritance
  • Polymorphism
  • Abstraction
The concept of creating a single function or method that can operate on multiple types of objects is known as "Polymorphism." In JavaScript, polymorphism can be achieved through method overriding and dynamic method binding, enabling different objects to respond to the same method in a way that suits their specific type.

How can you implement a while loop without causing a browser to freeze in case of a long-running process?

  • Use asynchronous code and setTimeout to break the loop into smaller chunks, allowing the browser to handle other tasks.
  • Wrap the loop in a Web Worker to offload it to a separate thread.
  • Increase the browser's JavaScript execution stack size to handle long-running loops.
  • Use a while loop with a higher timeout value to prevent freezing.
To prevent the browser from freezing during a long-running while loop, you should use asynchronous code and setTimeout to break the loop into smaller chunks. This allows the browser to handle other tasks and prevents the UI from becoming unresponsive. This approach follows the principles of non-blocking and responsive UI in web development.

The _______ method returns a Promise that resolves or rejects as soon as one of the promises in an iterable resolves or rejects, with the value or reason from that promise.

  • Promise.race()
  • Promise.all()
  • Promise.any()
  • Promise()
The correct answer is Promise.race(). This method takes an iterable of promises and returns a new promise that settles as soon as one of the input promises resolves or rejects. It's useful when you want to perform an action as soon as any of several asynchronous tasks completes.

The initial version of JavaScript was created in just _________ days.

  • 5 days
  • 10 days
  • 15 days
  • 20 days
The initial version of JavaScript was created in just 10 days by Brendan Eich in September 1995. This rapid development was possible due to the language's concise design and its primary purpose of enhancing web page interactivity.

What is "event bubbling" in JavaScript?

  • It refers to blowing up events like balloons.
  • It is the process of propagating events from child elements to parent elements in the DOM.
  • It is the automatic inflation of event objects.
  • It is a debugging technique in JavaScript.
"Event bubbling" in JavaScript refers to the process where events that occur on child elements are also propagated or "bubbled" up to their parent elements in the Document Object Model (DOM). This allows you to capture events at higher levels in the DOM hierarchy. Understanding event bubbling is crucial for event handling in JavaScript.

Which design principle is violated if a superclass is aware of its subclasses?

  • Encapsulation
  • Inheritance
  • Polymorphism
  • Abstraction
When a superclass is aware of its subclasses, it violates the principle of encapsulation. Encapsulation refers to the concept of bundling data and the methods that operate on that data into a single unit or class. In object-oriented programming, classes should not have direct knowledge of their subclasses to promote loose coupling and maintainability. Instead, subclasses should inherit behavior and attributes from the superclass without the superclass needing to know specific details about its subclasses. Violating this principle can lead to code that is less flexible and harder to maintain.

Which method is commonly used to change the text content of an HTML element using JavaScript?

  • innerHTML
  • setAttribute
  • appendChild
  • createTextNode
The innerHTML property is commonly used to change the text content of an HTML element using JavaScript. It allows you to set the HTML content of an element, including its text. For example, you can use element.innerHTML = "New Text" to change the content of an element.

To add elements to an array at a specific index, you might use _______.

  • addAt()
  • insert()
  • place()
  • set()
o add elements to an array at a specific index in JavaScript, you would typically use the splice() method. The splice() method allows you to specify the index where you want to add elements and the number of elements to remove (if any). This method can be used for both adding and removing elements at a specific position in an array. For example, myArray.splice(2, 0, 'newElement') would add 'newElement' at index 2 of myArray.

What is the primary purpose of classes in JavaScript?

  • Defining constants
  • Object creation
  • Error handling
  • Loop iteration
The primary purpose of classes in JavaScript is to facilitate object creation and define blueprints for objects. Classes act as templates for creating objects with shared properties and methods, enhancing code organization and reusability. While JavaScript does have constants, error handling, and loops, these are not the primary purposes of classes.

A potential issue with JavaScript's prototype chain is that properties added to the prototype are ________ among all objects created with that constructor function.

  • Shared
  • Encapsulated
  • Protected
  • Private
A potential issue with JavaScript's prototype chain is that properties added to the prototype are shared among all objects created with the same constructor function. This means that any modification to the prototype will affect all instances created from that constructor, which can lead to unexpected behavior.