# Why is checking closed subscheme a local problem

In the proof of Proposition 5.9 (page 116) of Hartshorne's Algebraic Geometry, he wrote

... we only have to check that $(Y, \mathscr{O}_X/\mathscr{I})$ is a closed subscheme [of X]. This is a local question, so we may assume $X = \text{Spec }A$ is affine.

I wonder what he meant by that. Is it true that $f : Y \rightarrow X$ is a closed immersion if and only if for any open affine cover $U_i$ of $X$, $f : f^{-1}(U_i) \rightarrow X$ is closed immersion?

EDIT: I just realize that this is true.