Which keyword is used to stop the loop prematurely?

  • break
  • continue
  • exit
  • return
The keyword used to stop a loop prematurely in JavaScript is "break." When "break" is encountered within a loop, it immediately exits the loop, even if the loop condition is still true or there are more iterations remaining. This is useful for early termination of a loop based on a specific condition. "continue" skips the current iteration and moves to the next one, while "exit" and "return" have different purposes and are not used for loop control.

During a job interview, you're asked about the evolution of JavaScript. The interviewer specifically wants to know about a major shift in JavaScript's usage from merely adding interactivity to web pages to being used in server-side programming. What technology or platform brought about this shift?

  • Node.js
  • Apache Tomcat
  • PHP
  • Ruby on Rails
JavaScript's major shift into server-side programming was largely enabled by Node.js. Node.js is a runtime environment that allows JavaScript to be executed on the server, making it suitable for building scalable, server-side applications. It revolutionized web development by unifying front-end and back-end languages.

Why might for...of loops be preferred when working with asynchronous code?

  • They can be used with any iterable object.
  • They automatically handle Promise resolution.
  • They are faster than traditional for loops.
  • They provide better error handling mechanisms.
For...of loops are preferred when working with asynchronous code because they automatically handle Promise resolution. When you iterate over an iterable that contains Promises, for...of will await each Promise and provide the resolved value, making it more convenient for working with asynchronous operations.

What is the primary difference between while and do-while loops in JavaScript?

  • The while loop always executes the code block at least once
  • The do-while loop is more efficient
  • The while loop is not suitable for iterating over arrays
  • The do-while loop doesn't have a condition
The primary difference is that in a while loop, the condition is checked before executing the code block. If the condition is initially false, the code block may never run. In contrast, the do-while loop guarantees that the code block is executed at least once because it checks the condition after executing the block. This makes do-while useful when you want the code to run once before checking the condition.

The ________ operator can be used to compare both value and type in JavaScript.

  • Equality (===)
  • Assignment (=)
  • Identity (==)
  • Inequality (!=)
The Equality (===) operator can be used to compare both value and type in JavaScript. It checks if two values are strictly equal, meaning they have the same value and the same data type. The other options, such as Assignment (=) and Identity (==), do not perform strict value and type comparison. Inequality (!=) checks for inequality.

The process of an object inheriting properties and behaviors (methods) from its prototype is known as _________.

  • Encapsulation
  • Inheritance
  • Polymorphism
  • Abstraction
Inheritance is the process by which an object inherits properties and behaviors (methods) from its prototype or parent object. JavaScript uses a prototype-based inheritance model, where objects inherit from other objects, and this is a fundamental concept in the language.

The ________ method is used to read a Response stream and return it as a blob.

  • text()
  • json()
  • blob()
  • arrayBuffer()
The blob() method is used to read a Response stream and return it as a blob object. This is commonly used when dealing with binary data or files. The other options (text(), json(), arrayBuffer()) are used for different types of Response data processing.

Which property of the Response object represents the status text of the response?

  • statusText
  • statusCode
  • status
  • statusDescription
The statusText property of the Response object represents the status text of the HTTP response. It provides a textual description of the HTTP status code, such as "OK" for status code 200 or "Not Found" for status code 404. This property is useful for understanding the meaning of the response status code in a more human-readable form.

The method _______ is used to sort the elements of an array.

  • sort()
  • splice()
  • split()
  • reduce()
The correct method is sort(). JavaScript arrays have a built-in sort() method that is used to sort the elements of an array in ascending order by default. You can also provide a compare function to customize the sorting behavior. For example, myArray.sort((a, b) => a - b) sorts the array numerically.

You're refactoring your code to improve performance and notice a function that returns another function, accessing variables outside of its own scope. What specific JavaScript concept should you consider when optimizing this code section?

  • Function Closures
  • Function Prototypes
  • Event Bubbling
  • AJAX (Asynchronous JavaScript and XML)
When optimizing code that returns a function and accesses variables outside of its own scope, you should consider the concept of function closures. Function closures allow an inner function to "remember" and access variables from its containing (parent) function's scope even after the parent function has finished executing. This can be useful for encapsulating state and optimizing code.