Which principle of object-oriented programming focuses on hiding internal implementation details and exposing only necessary information?
Encapsulation
Abstraction
Polymorphism
Inheritance
How can you ensure that the 'this' keyword inside a callback function refers to the intended object, especially in asynchronous operations?
By wrapping the callback function in another function.
By using the 'let' keyword to declare variables inside the callback.
By invoking the callback function with 'call()' or 'apply()'.
By using arrow functions, which lexically inherit the 'this' value.
Consider the code: const myFunc = (a, b) => a + b;. What type of function is myFunc?
const myFunc = (a, b) => a + b;
myFunc
Arrow function
Generator function
Constructor function
Method
What is the purpose of the 'performance.now()' method in JavaScript?
It provides the current time in milliseconds since the Unix epoch.
It schedules a function to run after a specified delay.
It clears a timer previously set with 'setTimeout'.
It measures the execution time of a specific code block with high precision.
Which tool is commonly used for profiling JavaScript code execution and identifying performance bottlenecks?
console.time()
JSON.stringify()
Chrome DevTools Performance Tab
Array.reduce()
What is the primary purpose of constructor functions in JavaScript?
To create multiple instances of an object with shared properties and methods.
To handle asynchronous operations.
To define private variables within a function scope.
To define static methods for a class.
You need to add an event listener to a dynamically created element. What technique should you use?
Attach the listener to the element's parent using event bubbling.
Use setTimeout to delay the listener attachment until after the element is added to the DOM.
setTimeout
Event delegation: attach the listener to a parent element that already exists in the DOM.
Directly attach the listener to the element before appending it to the DOM.
In the context of ES6 classes, what is the purpose of the 'extends' keyword?
It extends the functionality of a built-in JavaScript object like Array or String.
It establishes inheritance by creating a subclass that inherits properties and methods from a superclass.
It's used to create an instance of a parent class.
It defines a new static method within a class.
Which HTTP status code range generally indicates a successful request made with the Fetch API?
400-499
200-299
100-199
300-399
Which built-in JavaScript method allows you to pass an array of arguments to a function, effectively spreading them as individual arguments?
bind()
apply()
call()
spread()