Discontinuous functions with closed graphs

$f\colon\mathbb{R}\to\mathbb{R}$ defined by $$ f(x)=\frac1x\quad\text{if}\quad x\ne0,\quad f(0)=0. $$


I'd like to answer the comment about why the graph is closed (particularly as it also took me a while to see it).

To see that the graph of $f\colon\mathbb{R}\to\mathbb{R}$ defined by $$ f(x)=\frac1x\quad\text{if}\quad x\ne0,\quad f(0)=0. $$ is closed consider the equivalent definition of a closed graph in a metric space. $G(f)$ is closed if whenever $(x_n) \to x$ and $(f(x_n)) \to y$ then $y = f(x)$. (This follows since in a metric space closure is equivalent to sequential closure and convergence in the product space is equivalent to convergence of the components)

Now for $(x_n) \to 0$ then $(f(x_n))$ is not convergent so $(x_n) \to x$ and $(f(x_n)) \to y$ is not satisfied, while for every other sequence $(x_n) \to x \ne 0$ then $(f(x_n)) \to f(x)$.

So it is true that whenever $(x_n) \to x$ and $(f(x_n)) \to y$ then $y = f(x)$ and therefore $G(f) $ is closed.