XJavascript.com
Toggle Menu
Home
Online Javascript Compiler
Tutorials
JavaScript Tutorials
TypeScript Tutorials
Blog
All Posts
Performance Optimization in JavaScript
Assess techniques to improve JS app speed and efficiency.
1. Which technique limits the rate at which a function is called by ensuring it runs only once after a certain period of inactivity?
Debouncing
Throttling
Memoization
Caching
2. What does 'code splitting' in JavaScript primarily aim to optimize?
Load time by reducing initial bundle size
Runtime speed by minifying code
Memory usage by garbage collection
CPU usage by async functions
3. Which DOM operation is most likely to cause a reflow (layout thrashing)?
Reading offsetHeight
Changing className
Using documentFragment
Setting display: none
4. Event delegation leverages which event behavior to improve performance?
Event bubbling
Event capturing
Event propagation
Event cancellation
5. Memoization optimizes function performance by:
Caching results of expensive function calls
Minifying function code
Splitting function into smaller parts
Delaying function execution
6. Which loop is generally most efficient for iterating over a large array in JavaScript?
for loop (index-based)
for...of
forEach
while loop
7. What attribute should be added to a script tag to load it asynchronously without blocking HTML parsing?
async
defer
async="true"
load="async"
8. Why are global variables detrimental to performance?
They persist in memory longer, causing higher memory usage
They are slower to access due to longer scope chain lookup
They prevent garbage collection if not dereferenced
All of the above
9. Which of the following are common causes of memory leaks in JavaScript? (Select all that apply)
Unremoved event listeners
Closures retaining large objects
Using let instead of var
Timers (setInterval) with no clearInterval
10. Which practices help minimize reflows (layout thrashing) and repaints? (Select all that apply)
Batching DOM reads before writes
Using requestAnimationFrame for visual updates
Modifying the DOM multiple times in a loop
Applying CSS transforms instead of top/left
11. Which resources are commonly lazy loaded to improve initial page performance? (Select all that apply)
Images
JavaScript bundles
Critical CSS stylesheets
Fonts
12. Which DOM query methods are most efficient for performance? (Select all that apply)
getElementById
querySelector('#id')
getElementsByClassName
querySelectorAll('div .class')
13. In which scenarios is memoization most effective? (Select all that apply)
Pure functions with repeated identical inputs
Functions with side effects
Recursive functions with repeated subproblems
Functions with frequently changing arguments
14. Using 'let' instead of 'var' improves JavaScript performance by reducing memory usage.
True
False
15. Event delegation can reduce the number of event listeners attached to the DOM, improving performance.
True
False
16. Minifying JavaScript code improves runtime performance by making the code execute faster.
True
False
17. Using 'requestIdleCallback' allows non-critical work to be executed during browser idle periods, improving responsiveness.
True
False
18. What is the process of automatically freeing up memory by removing unused objects that are no longer referenced? (two words)
19. Name the technique that delays the loading of non-critical resources (e.g., images) until they enter the viewport (two words)
20. What is the name of the JavaScript API that allows running scripts in background threads to avoid blocking the main thread (plural noun)
Reset
Answered 0 of 0 — 0 correct