For all nonempty $A \subset X$ the function “least distance to $A$” given by $$x \mapsto \operatorname{dist}{(x,A)} = \inf\limits_{a \in A}\;d(x,a)$$ is continuous (even $1$-Lipschitz) and it is zero precisely on the closure of $A$, see this thread for some proofs of that fact.

If $A \neq \emptyset$ is closed then $A = \{x \in X\,:\,\operatorname{dist}(x,A) = 0\}$. If $A = \emptyset$ take a constant non-zero function.