What is a primary method for avoiding memory leaks in JavaScript?
Dereferencing unused objects and variables
Minimizing function calls
Using 'async/await' for all asynchronous operations
Using 'const' for all variable declarations
What is the primary purpose of Promises in JavaScript?
To define object-oriented classes.
To handle synchronous operations more efficiently.
To create loops that iterate over arrays.
To manage asynchronous operations and their results.
What is the primary role of the this keyword in JavaScript?
this
It creates a new object instance.
It accesses the global scope.
It refers to the current date and time.
It points to the object that the function is a property of, determined at function call time.
What does the 'Fetch API' return as the result of a successful network request?
A Promise that resolves to a Response object.
An error object indicating a failed request.
A callback function for handling the response.
The requested data directly as a JavaScript object.
Which technique can minimize DOM reflows and repaints, leading to smoother UI updates?
Making changes to elements with 'display: none'
Frequently reading element properties like 'offsetWidth'
Using 'innerHTML' to update large sections of the DOM
Batching DOM updates and using 'requestAnimationFrame'
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 a common way to achieve encapsulation in JavaScript when modules are not an option (e.g., in older environments)?
Relying solely on comments to indicate private members, as there are no built-in mechanisms for true privacy.
Using global variables to store private data.
Encapsulation is not achievable without modules in JavaScript.
Leveraging closures to create private scopes and control access to variables and functions within those scopes.
Which built-in JavaScript method allows you to pass an array of arguments to a function, effectively spreading them as individual arguments?
spread()
apply()
call()
bind()
How does the 'bind()' method in JavaScript differ from 'call()' and 'apply()'?
bind() immediately invokes the function, while call() and apply() don't.
bind() can only be used with object methods, while call() and apply() can be used with any function.
bind() creates a new function with a bound 'this' context, while call() and apply() invoke the function immediately.
bind() doesn't modify the original function, while call() and apply() do.
What is the purpose of the 'performance.now()' method in JavaScript?
It provides the current time in milliseconds since the Unix epoch.
It measures the execution time of a specific code block with high precision.
It schedules a function to run after a specified delay.
It clears a timer previously set with 'setTimeout'.