An arrow function is defined using the _________ symbol.
- =>
- ->
- function
- =
An arrow function is defined using the => (fat arrow) symbol. This concise syntax is a shorthand for writing simple, one-liner functions in JavaScript. It's especially useful for functions that have no side effects and return a single expression. The => symbol distinguishes arrow functions from traditional function declarations.
The data type of NaN in JavaScript is _________.
- Not a Number (NaN)
- Number
- Undefined
- String
The data type of NaN in JavaScript is "Not a Number" (NaN). NaN is a special value representing an unrepresentable or undefined value in the context of numbers. It is not a regular number, undefined, or a string. Understanding the data type of NaN is important for handling unexpected mathematical operations in JavaScript.
You are building a single-page application, and you want to make an API call. You realize that you want to abort the fetch request if the user navigates away from the current page to avoid unnecessary data transfer. How can you achieve this?
- Use the fetch.abort() method to cancel the request when the user navigates away.
- Implement an if statement to check the navigation state and cancel the request accordingly.
- Set a timeout for the fetch request and cancel it if the user navigates away within the timeout period.
- There's no way to cancel a fetch request when the user navigates away.
To abort a fetch request when the user navigates away from the current page, you should implement an if statement that checks the navigation state and cancels the request accordingly. The other options are not suitable for this specific task, and there's no built-in fetch.abort() method in JavaScript.
You're reviewing a pull request, and you see that a developer used var to declare a variable inside a for loop. You notice that the variable is being accessed outside the loop without any issues. Why is this possible?
- Variable Hoisting
- Block Scoping (let/const)
- Function Scoping
- Global Scope
This is possible due to "Variable Hoisting" in JavaScript. Variables declared with var are hoisted to the top of their containing function or global scope. This means that the variable is accessible anywhere within that scope, even before its actual declaration in the code.
The break statement exits a while loop and continues executing the code that follows the loop at line number ________.
- immediately
- next
- specified
- labeled
The 'break' statement exits a while loop immediately and continues executing the code that follows the loop at the next line. It allows you to prematurely terminate a loop based on a certain condition, without completing the remaining iterations.
You are developing a system where you have a base class "User" and two derived classes "Admin" and "Guest". If you want to add a method that is only applicable for "Admin" and not for "Guest", where should you add that method to adhere to the Liskov Substitution Principle?
- In the "User" class
- In the "Admin" class
- In the "Guest" class
- In a separate utility function
To adhere to the Liskov Substitution Principle, you should add the method specific to "Admin" in the "Admin" class. This ensures that each derived class (Admin and Guest) can be used interchangeably with the base class (User) without violating the principle.
You are designing a car simulation game using JavaScript. Each type of car (e.g., sedan, truck, etc.) has different methods for calculating fuel efficiency. Which object-oriented programming concept would be most appropriate to ensure that each car type can calculate fuel efficiency in its own way, while still inheriting basic characteristics from a general Car class?
- Inheritance
- Polymorphism
- Encapsulation
- Abstraction
Polymorphism allows different car types (e.g., sedan, truck) to have their own implementations of the fuel efficiency calculation method while inheriting common attributes and behaviors from the general Car class. This ensures flexibility and extensibility in your game.
A _________ function expression can be named, providing a reference to itself.
- Recursive
- IIFE (Immediately Invoked Function Expression)
- Anonymous
- Callback
A recursive function expression can be named, allowing it to refer to itself by name. This is useful in cases where a function needs to call itself during its execution, typically seen in solving recursive problems or implementing recursive algorithms.
The method getElementById selects an element using its ______.
- ID
- Tag Name
- Class Name
- Attribute
The method getElementById selects an element by its ID attribute. It returns the element with the specified ID attribute, providing a direct and efficient way to access an element in the DOM by its unique identifier.
To avoid iterating over prototype properties with for...in, you should use the _______ method.
- Object.keys
- hasOwnProperty
- Object.prototype
- Object.values
To avoid iterating over prototype properties with a for...in loop, you should use the Object.keys method. This method returns an array of an object's own enumerable property names, allowing you to iterate over only the object's properties without including those from its prototype chain.