What is a higher-order function in JavaScript?
A function that can only be called once.
A function that uses arrow syntax.
A function that does not have a return statement.
A function that takes another function as an argument or returns a function.
Which principle of object-oriented programming focuses on hiding internal implementation details and exposing only necessary information?
Encapsulation
Abstraction
Polymorphism
Inheritance
What is the primary difference between 'nextSibling' and 'nextElementSibling' in DOM traversal?
There is no difference; they are interchangeable.
'nextSibling' traverses upwards in the DOM, while 'nextElementSibling' traverses downwards.
'nextSibling' might return a text node or comment, while 'nextElementSibling' only returns element nodes.
'nextSibling' only works with elements, while 'nextElementSibling' works with any node type.
What is the purpose of the 'performance.now()' method in JavaScript?
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'.
It provides the current time in milliseconds since the Unix epoch.
How does the 'bind()' method in JavaScript differ from 'call()' and 'apply()'?
bind() doesn't modify the original function, while call() and apply() do.
bind() creates a new function with a bound 'this' context, while call() and apply() invoke the function immediately.
bind() can only be used with object methods, while call() and apply() can be used with any function.
bind() immediately invokes the function, while call() and apply() don't.
Which tool is commonly used for profiling JavaScript code execution and identifying performance bottlenecks?
Chrome DevTools Performance Tab
console.time()
JSON.stringify()
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 define private variables within a function scope.
To define static methods for a class.
To handle asynchronous operations.
What will be logged to the console in this code snippet: console.log((function(a) { return a * a; })(5));?
console.log((function(a) { return a * a; })(5));
5
10
25
undefined
You want to remove the third child element from a parent element with the ID 'container'. What is the correct JavaScript code?
document.getElementById('container').childNodes[2].remove();
document.getElementById('container').children[2].remove();
document.getElementById('container').deleteChild(2);
document.getElementById('container').removeChild(2);
What is a key difference between 'async/await' and traditional Promise-based code?
'async/await' provides a more synchronous-looking syntax for asynchronous code.
'async/await' is significantly slower than using Promises directly.
'async/await' doesn't use Promises internally.
'async/await' is suitable for handling synchronous operations only.