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.
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.
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.
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.
Which of the following is NOT an argument passed to an event listener when it is invoked?
- event
- target
- type
- timestamp
When an event listener is invoked, it receives an event object containing information about the event. It also has access to the target (the element that triggered the event) and type (the type of event). However, timestamp is not an argument passed to an event listener. It can be obtained using event.timeStamp.
A(n) _______ function returns a promise.
- Synchronous
- Callback
- Async
- Static
An Async function returns a promise implicitly. When you declare a function as async, it means the function will always return a promise, allowing you to use await inside it to handle asynchronous operations more cleanly.
The ________ method is used to parse a JSON string into a JavaScript object.
- toJSON()
- parseJSON()
- JSON.parse()
- stringToJSON()
The correct method to parse a JSON string into a JavaScript object is JSON.parse(). It takes a JSON string as input and returns a JavaScript object. The other options (toJSON(), parseJSON(), stringToJSON()) are not valid JSON parsing methods.
What is the primary use of the switch statement in JavaScript?
- To declare variables
- To create loops
- To perform conditional branching
- To define functions
The primary use of the switch statement in JavaScript is to perform conditional branching. It allows you to execute different code blocks based on the value of an expression, making it a powerful tool for decision-making in your code.
How can a subclass be created in JavaScript?
- Using the extends keyword
- By defining a new class with the same name
- Using the super keyword
- By using the inherit keyword
In JavaScript, you can create a subclass by using the extends keyword. This allows you to inherit the properties and methods of another class, forming a class hierarchy. The extends keyword establishes a relationship between the subclass and the superclass.
The ______ statement is used to specify a block of code to be executed if the condition is false.
- if-else
- else-if
- if
- switch
The "else" statement is used to specify a block of code to be executed if the condition specified in the preceding "if" statement is false. It allows for conditional execution, and if the "if" condition is not met, the code inside "else" will be executed.