Browser & Web Performance · Middle · Question 1 of 75

What problem does this code cause?

for (const card of cards) {
  const h = card.offsetHeight;
  card.style.height = h + 10 + "px";
}

Explanation

Reading geometry after changing styles forces the browser to recalculate layout immediately. Batch all reads first, then all writes.

Further reading

Problem with a question

Browser & Web Performance · Middle · question 1

Test yourself

Take the Browser & Web Performance · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz