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.

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.

While working with React, you notice a function defined using the function keyword is not updating the component state as it should. You suspect it's related to the "this" keyword. What might be the problem?

  • The function should be an arrow function
  • "this" in a React component refers to the element
  • "this" in a React component refers to the component
  • The function lacks proper binding
In React, when using the function keyword to define a custom method within a component class, you need to manually bind the function to the component instance in the constructor using "this.functionName = this.functionName.bind(this);" to ensure that "this" refers to the component instance and not the function itself.

What happens when a function declaration and a var variable are hoisted in the same scope?

  • The var variable takes precedence and shadows the function declaration.
  • The function declaration takes precedence and shadows the var variable.
  • JavaScript throws an error since function declarations and var variables can't be hoisted in the same scope.
  • They both coexist in the same scope, and there's no shadowing or precedence.
When a function declaration and a var variable with the same name are hoisted in the same scope, the function declaration takes precedence and shadows the var variable. This is known as "hoisting," and it means that the function is accessible throughout the scope, even before its actual declaration in the code.

The property event.target gives access to the _________ that triggered the event.

  • element
  • object
  • source
  • target
The event.target property in JavaScript gives access to the element that triggered the event. It's especially useful in event delegation and can be used to identify which specific element was interacted with in a group of similar elements.

It’s possible to create a switch-like behavior using object literals and the _________ method in JavaScript.

  • forEach()
  • map()
  • reduce()
  • hasOwnProperty()
It’s possible to create a switch-like behavior using object literals and the hasOwnProperty() method in JavaScript. By defining properties in an object literal and then checking if a specific property exists using hasOwnProperty(), you can achieve similar branching behavior as a switch statement.

How can you prematurely terminate a while loop?

  • break statement
  • return statement
  • continue statement
  • exit statement
You can prematurely terminate a while loop using the break statement. When a break statement is encountered within the loop, it exits the loop prematurely, regardless of whether the loop's condition is still true. This is useful for stopping the loop when a specific condition is met.

If you’re using arrow functions to define methods inside a class, those methods will not have access to the class’s instance without using _________.

  • super()
  • this
  • prototype
  • new
If you use arrow functions to define methods within a class, they will not have their own this context. Instead, they inherit the this context from the surrounding scope. To access the class instance within an arrow function, you need to use this. Hence, the correct option is this.

In Internet Explorer, instead of addEventListener, the _________ method is used to attach event listeners.

  • attachEvent()
  • registerListener()
  • listenForEvent()
  • addListener()
In Internet Explorer, the attachEvent() method is used to attach event listeners. This method is specific to Internet Explorer and serves a similar purpose to addEventListener() in other browsers, allowing you to respond to events such as clicks and keypresses.

In JavaScript, a common way to utilize prototypes is by assigning a(n) _________ to an object's prototype property.

  • Array
  • Object Literal
  • Constructor Function
  • Prototype Object
In JavaScript, prototypes are often utilized by assigning a constructor function to an object's prototype property. This constructor function serves as a blueprint for creating objects with shared properties and methods. The prototype object associated with this constructor contains those shared properties and methods.

You are developing a function that needs to maintain state between calls without using global variables. Which JavaScript feature would you utilize to achieve this?

  • Closures
  • Prototypes
  • Callbacks
  • Promises
You can utilize closures in JavaScript to maintain state between function calls without relying on global variables. A closure is a function that has access to variables from its outer (enclosing) function's scope, even after the outer function has finished executing. This allows you to create private variables and maintain state within the closure function.

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.