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.

What will happen if the break statement is omitted in a switch case?

  • The program will continue to execute the following case(s) until a break or the end of the switch.
  • It will skip the current case and move on to the default case.
  • It will throw a syntax error.
  • It will automatically add a break statement, preventing fall-through.
If you omit the break statement in a switch case, JavaScript will execute the code for that case and continue to execute the code for the following case(s) until it encounters a break statement or reaches the end of the switch statement. This behavior is known as "fall-through."

The keyword ______ is used to specify a block of code to be executed, if the same block that it is directly proceeding does not get executed.

  • break
  • continue
  • return
  • finally
The keyword finally is used to specify a block of code that will be executed regardless of whether an exception is thrown or not in a try...catch block. It ensures that cleanup code is always executed.

You are working on a web application where you need to fetch data from an API, perform operations on it, and then use it to update the UI. Which JavaScript feature allows you to handle these asynchronous operations more readably and reliably?

  • Callback Functions
  • Promises
  • Event Loop
  • Callback Hell
Promises in JavaScript allow you to handle asynchronous operations more readably and reliably. Promises provide a structured way to work with asynchronous code, making it easier to manage tasks like fetching data from an API, performing operations, and updating the UI when the data is ready.

Which keyword is used to declare a variable with block scope?

  • let
  • var
  • const
  • block
The let keyword is used to declare a variable with block scope in JavaScript. Variables declared with let are limited to the block or scope in which they are defined, which is typically within a pair of curly braces {}.

Which early browser first implemented JavaScript?

  • Internet Explorer
  • Mosaic
  • Netscape Navigator
  • Opera
JavaScript was first implemented in Netscape Navigator. Brendan Eich developed it in 1995 while working at Netscape Communications. This move by Netscape added a significant interactive element to the web and contributed to the rapid adoption of JavaScript.

How does the for...of loop handle string iteration?

  • It iterates over each character in the string.
  • It treats the string as an iterable object.
  • It only works on single-character strings.
  • It throws an error when used with strings.
The for...of loop handles string iteration by iterating over each character in the string. It treats the string as an iterable object where each character is an element, allowing you to loop through and process individual characters in a string efficiently.

What is the purpose of the default case in a switch statement?

  • It defines a fallback case
  • It specifies the first case
  • It is used for loop control
  • It marks the end of the switch
The default case in a switch statement serves as a fallback option. If none of the other cases match the expression's value, the code in the default case block is executed. This ensures that there is always a valid path in the switch.

Which of the following scenarios is NOT recommended for using arrow functions?

  • As event handlers in the DOM.
  • As methods within objects.
  • In callbacks where "this" context matters.
  • In short, simple functions.
Arrow functions are not recommended for use as event handlers in the DOM. This is because the value of "this" in an arrow function is not determined by the event but instead retains the value from its enclosing lexical context, which may not be what you expect in an event handler. Traditional functions are usually preferred for event handlers.