JavaScript · Senior · Question 18 of 75

Why is ResizeObserver better than a window.resize handler for a component?

Explanation

An element can change size without the window changing: a sidebar opened, content loaded. ResizeObserver tracks the element itself and is called in the rendering cycle, without polling getBoundingClientRect. Useful for charts and virtualized lists.

Further reading

Problem with a question

JavaScript · Senior · question 18

Test yourself

Take the JavaScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz