Unlike function expressions, function declarations are _________.

  • Hoisted
  • Anonymous
  • Scoped
  • Encapsulated
Unlike function expressions, function declarations are hoisted. This means they are moved to the top of their containing scope during compilation, allowing you to call them before they are defined in the code. Function expressions are not hoisted in the same way.

JavaScript was initially designed to make web pages more _________.

  • Interactive
  • Static
  • Secure
  • Colorful
JavaScript was initially designed to make web pages more interactive. It allowed developers to create dynamic and engaging web content by manipulating elements on web pages in response to user actions. This interactivity revolutionized web development.

How can you handle exceptions within a "for" loop to prevent it from being terminated prematurely?

  • By wrapping the entire loop in a try-catch block
  • By using the "continue" statement
  • By adding a "finally" block after the loop
  • By setting a maximum execution time for the loop
To handle exceptions within a "for" loop, you can wrap the entire loop in a try-catch block. This allows you to catch and handle exceptions that occur during the loop's execution, preventing it from being terminated prematurely. The other options do not directly address exception handling within the loop.

How does an arrow function handle the "this" keyword differently than regular functions?

  • Arrow functions inherit the "this" value from their containing scope.
  • Arrow functions have their own "this" context.
  • Arrow functions automatically bind "this" to the global object.
  • Arrow functions can't use "this" keyword.
Arrow functions behave differently from regular functions when it comes to the "this" keyword. They inherit the "this" value from their containing lexical (surrounding) scope, while regular functions have their "this" determined by how they are called. This behavior can be advantageous in certain situations.

The _________ method is used to bind an object context to a function and is called immediately.

  • Bind
  • Apply
  • Call
  • Invoke
The "call" method in JavaScript is used to bind an object's context to a function and is called immediately. It allows you to specify the value of "this" explicitly when invoking a function, along with any additional arguments you want to pass to the function.

How does event looping handle while(true) in Node.js environments?

  • It blocks the event loop indefinitely, causing the application to hang.
  • It executes the loop in a separate thread to avoid blocking.
  • It sets a maximum execution time for the loop to prevent hanging.
  • It queues the while(true) in the event loop, allowing other events to execute.
In Node.js, using while(true) will block the event loop indefinitely, causing the application to hang. This is because Node.js is single-threaded and relies on an event loop to handle asynchronous tasks. Long-running synchronous code like while(true) can prevent other tasks from being executed.

In a do-while loop, when is the condition checked?

  • Before executing the code block
  • After executing the code block
  • During the execution of the code block
  • It's not checked in a do-while loop
In a do-while loop, the condition is checked after executing the code block. This means that the code block will always execute at least once before the condition is evaluated. If the condition is true after the first execution, the loop will continue running; otherwise, it will exit. This makes do-while loops suitable when you want to ensure that a specific task is performed before checking the condition.

Imagine you’re refactoring a piece of code that involves a series of callback functions into a format that uses async/await. What should you pay extra attention to regarding error handling when refactoring the code?

  • Ensure proper try/catch
  • Maintain callback structure
  • Avoid async/await
  • Ignore error handling entirely
When refactoring code to use async/await, it's crucial to ensure proper error handling. This means using try/catch blocks around await operations to catch and handle any exceptions that may occur during asynchronous operations. Neglecting error handling could lead to unhandled exceptions and unexpected behavior.

The switch statement in JavaScript uses _________ comparison to evaluate cases.

  • Strict (===)
  • Loose (==)
  • Greater (>)
  • Lesser (<)
The switch statement in JavaScript uses strict (===) comparison to evaluate cases. This means that not only the value but also the data type must match for a case to be executed. This ensures accuracy when comparing values in a switch statement.

When using the new keyword to create an object, what kind of function must you use?

  • Regular Function Declaration
  • Arrow Function
  • Constructor Function
  • Prototype Function
When using the new keyword to create an object, you must use a Constructor Function. Constructor functions are used to create and initialize objects. They are invoked with the new keyword and often set object properties and methods within the constructor. Arrow functions are not suitable because they don't have their own this context.