How can you remove an HTML element using JavaScript?

  • remove()
  • hide()
  • deleteElement()
  • innerHTML = ''
You can remove an HTML element using the remove() method in JavaScript. For example, if you have an element with the ID elementToRemove, you can remove it using document.getElementById('elementToRemove').remove();. This method completely removes the element from the DOM (Document Object Model).

If no case matches in a switch statement and there is no default case, the control is passed to the _________.

  • Next statement
  • Previous case
  • Last case
  • Next iteration
If no case matches in a switch statement and there is no default case, the control is passed to the next statement after the switch. This behavior is important to understand because it determines what happens when none of the cases match the expression value.

The for...in loop will also iterate over the _______ properties of an object.

  • Enumerable
  • Non-enumerable
  • Private
  • Prototype
The for...in loop will also iterate over the enumerable properties of an object. Enumerable properties are those that can be iterated over using for...in, typically the object's own properties. Non-enumerable properties, private properties, and prototype properties are not included in this iteration.

What was the main reason for JavaScript's creation at Netscape?

  • To compete with Microsoft's JScript
  • To create a replacement for HTML
  • To enhance interactivity in web browsers
  • To provide a server-side scripting language
JavaScript was primarily created to enhance interactivity in web browsers. It allowed developers to manipulate web page elements and respond to user actions, making websites more dynamic. While JavaScript later found uses on the server-side as well, its initial purpose was to enhance the client-side user experience.

Which of the following is a way to create a singleton object in JavaScript?

  • Using the Factory Pattern
  • Using the Prototype Pattern
  • Using the Singleton Pattern
  • Using the Module Pattern
A singleton object in JavaScript is typically created using the Module Pattern. The Module Pattern allows you to encapsulate code and create a single instance of an object, ensuring that only one instance of the object exists throughout your application. The other options (Factory, Prototype, and Singleton patterns) serve different purposes.

What is the primary difference between for...in and for...of loops?

  • The order of iteration and syntax
  • The type of objects they iterate over
  • They are interchangeable
  • The number of iterations they perform
The primary difference between for...in and for...of loops is in their order of iteration and syntax. For...in is used for iterating over object properties, while for...of is used for iterating over the values of iterable objects, like arrays and strings, and maintains the order.

What is the primary purpose of using AJAX in web development?

  • To make synchronous requests to the server
  • To create web animations
  • To make asynchronous requests to the server
  • To validate HTML forms
The primary purpose of using AJAX in web development is to make asynchronous requests to the server without requiring a full page refresh. This allows for dynamic content loading and improved user experience in web applications.

What is a prototype in JavaScript?

  • A template object used for inheritance
  • A built-in JavaScript function for mathematical operations
  • An array of data
  • A type of loop construct
In JavaScript, a prototype is a template object that is used for inheritance. Each object in JavaScript has a prototype, and it allows objects to inherit properties and methods from other objects, creating a hierarchy of objects. Prototypal inheritance is a fundamental concept in JavaScript's object model.

Why does 0.1 + 0.2 !== 0.3 in JavaScript?

  • JavaScript has floating-point precision limitations
  • 0.1 and 0.2 are not stored precisely in binary
  • It's a bug in JavaScript
  • JavaScript uses a different numeric system
In JavaScript, numbers are represented in binary, and not all decimal fractions can be precisely represented in binary. Due to this limitation, when you perform operations like addition with decimal numbers, you might encounter tiny rounding errors that make 0.1 + 0.2 !== 0.3. This behavior is not unique to JavaScript and occurs in many programming languages with floating-point arithmetic.

You need to filter out the prototype properties while using a loop to iterate over object properties. Which loop would you use, and what additional method would be needed to avoid iterating over prototype properties?

  • for...in loop with hasOwnProperty()
  • for...of loop with Object.keys()
  • while loop with Object.getOwnPropertyNames()
  • forEach() method with Object.getOwnPropertyNames()
You would use a for...of loop with Object.keys() to iterate over object properties while excluding prototype properties. Object.keys() returns an array of an object's own enumerable property names, ensuring that prototype properties are filtered out.

Consider a function that fetches user information from an API. If the API call fails, you want to log an error message and then continue the execution of the function without throwing an exception to the outer scope. Which Promise method should you use to achieve this?

  • Promise.catch()
  • Promise.finally()
  • Promise.reject()
  • Promise.resolve()
You should use Promise.catch() to handle errors in a Promise. This method allows you to specify a callback function that will be called when the Promise is rejected, allowing you to log an error message and gracefully continue execution without propagating the error to the outer scope.

The HTTP status code ________ indicates that the request has succeeded.

  • 200 OK
  • 204 No Content
  • 404 Not Found
  • 500 Internal Server Error
The HTTP status code 200 OK indicates that the request has succeeded. It is the standard response for successful HTTP requests. The other options represent different HTTP status codes with different meanings, such as 'No Content,' 'Not Found,' and 'Internal Server Error.'