Which HTTP status code represents a successful GET request?

  • 200
  • 300
  • 400
  • 500
The HTTP status code '200' indicates a successful GET request. It means that the request was received, understood, and the server has responded with the requested data. Other status codes like 300 (redirect), 400 (client error), and 500 (server error) signify different types of issues or responses. Understanding status codes is crucial for handling HTTP requests properly in JavaScript.

How can you add a new item to the beginning of an array?

  • arr.unshift(newItem);
  • arr.push(newItem);
  • arr.append(newItem);
  • arr.insert(0, newItem);
To add a new item to the beginning of an array in JavaScript, you can use the arr.unshift(newItem); method. This will insert newItem at the start of the array, shifting the existing elements to the right. push() adds to the end of the array, append() and insert() are not standard array methods.

What will the for...of loop iterate over in an array?

  • Indexes of the array
  • Property names of the array
  • Values of the array
  • The array itself
The for...of loop is used to iterate over the values of an array, making it useful for accessing the elements directly. Unlike the for...in loop, which iterates over properties, for...of provides a simple way to loop through the contents of an array.

You want to select an element with the ID 'special' using JavaScript. However, your code isn't working as expected. What could be the possible reason if the HTML structure is correct?

  • Typo in the ID selector
  • Missing JavaScript library inclusion
  • The element is hidden by CSS
  • Case sensitivity issues
If your code to select an element by its ID isn't working, one possible reason could be a typo in the ID selector. IDs are case-sensitive, so make sure it matches the ID attribute in the HTML exactly. The other options are less likely causes: missing libraries would generally cause JavaScript errors, and CSS hiding doesn't affect element selection.

How does the for...of loop handle objects by default?

  • It iterates over the properties.
  • It throws an error.
  • It iterates over the values.
  • It iterates over the keys.
The for...of loop in JavaScript is used for iterating over iterable objects like arrays, strings, maps, and sets. By default, it iterates over the values of an iterable, making it a convenient choice for iterating through the elements of an array or the characters of a string, for example. It doesn't work with plain objects (non-iterable) and would require additional steps or methods to iterate over object properties.

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.

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.

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.

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.