What is the impact on performance when using a switch statement versus multiple if-else statements for numerous conditions?

  • Switch statements are generally faster than multiple if-else statements for numerous conditions because they use direct lookup tables.
  • Switch statements are slower than multiple if-else statements for numerous conditions due to increased code complexity.
  • There is no significant difference in performance between switch and if-else statements for numerous conditions.
  • Switch statements are slower due to the need for explicit type conversions.
Using a switch statement is often more performant when dealing with numerous conditions because it uses direct lookup tables, making it faster and more efficient than a series of if-else statements, which involve sequential comparisons.

You are developing a system where you have a base class "User" and two derived classes "Admin" and "Guest". If you want to add a method that is only applicable for "Admin" and not for "Guest", where should you add that method to adhere to the Liskov Substitution Principle?

  • In the "User" class
  • In the "Admin" class
  • In the "Guest" class
  • In a separate utility function
To adhere to the Liskov Substitution Principle, you should add the method specific to "Admin" in the "Admin" class. This ensures that each derived class (Admin and Guest) can be used interchangeably with the base class (User) without violating the principle.

You are designing a car simulation game using JavaScript. Each type of car (e.g., sedan, truck, etc.) has different methods for calculating fuel efficiency. Which object-oriented programming concept would be most appropriate to ensure that each car type can calculate fuel efficiency in its own way, while still inheriting basic characteristics from a general Car class?

  • Inheritance
  • Polymorphism
  • Encapsulation
  • Abstraction
Polymorphism allows different car types (e.g., sedan, truck) to have their own implementations of the fuel efficiency calculation method while inheriting common attributes and behaviors from the general Car class. This ensures flexibility and extensibility in your game.

A _________ function expression can be named, providing a reference to itself.

  • Recursive
  • IIFE (Immediately Invoked Function Expression)
  • Anonymous
  • Callback
A recursive function expression can be named, allowing it to refer to itself by name. This is useful in cases where a function needs to call itself during its execution, typically seen in solving recursive problems or implementing recursive algorithms.

The method getElementById selects an element using its ______.

  • ID
  • Tag Name
  • Class Name
  • Attribute
The method getElementById selects an element by its ID attribute. It returns the element with the specified ID attribute, providing a direct and efficient way to access an element in the DOM by its unique identifier.

To avoid iterating over prototype properties with for...in, you should use the _______ method.

  • Object.keys
  • hasOwnProperty
  • Object.prototype
  • Object.values
To avoid iterating over prototype properties with a for...in loop, you should use the Object.keys method. This method returns an array of an object's own enumerable property names, allowing you to iterate over only the object's properties without including those from its prototype chain.

The concept that allows JavaScript objects to inherit properties and behavior from an object of another class is known as _________.

  • inheritance
  • extension
  • encapsulation
  • polymorphism
The concept that allows JavaScript objects to inherit properties and behavior from an object of another class is known as "inheritance." Inheritance is a fundamental aspect of object-oriented programming and helps in code reusability.

Which keyword is used to check a condition in JavaScript?

  • for
  • if
  • while
  • switch
The keyword used to check a condition in JavaScript is if. It allows you to execute a block of code if a specified condition evaluates to true. The if statement is fundamental for controlling the flow of your JavaScript program.

How can you remove an HTML element using JavaScript?

  • remove()
  • hide()
  • deleteElement()
  • innerHTML = ''
You can remove an HTML element using the remove() method in JavaScript. For example, if you have an element with the ID elementToRemove, you can remove it using document.getElementById('elementToRemove').remove();. This method completely removes the element from the DOM (Document Object Model).

The comparison operator _______ checks for inequality, considering type coercion.

  • ==
  • ===
  • !=
  • !==
The comparison operator '!==' checks for inequality while also considering type coercion. It returns true if the values are not equal or if their types are not the same. For example, 5 !== "5" would evaluate to true because the number 5 is not equal to the string "5."