Consider $f:\mathbb R\to\overline{\mathbb R}$ defined as $f(x)=\begin{cases}\frac{1}{x}, x\neq 0\\ \infty, x=0 \end{cases}$
$f$ is Borel-measurable:
Proof (of Daniel Wainfleet).
It suffices to prove that if $U$ is open in $\overline {\Bbb R}$ then $f^{-1}U$ is Borel in $\Bbb R.$
Let $g$ be the restriction of $f$ to the domain $D=\Bbb R$ \ $\{0\}.$ Now $D$ is open in $\Bbb R$ and $g:D\to \Bbb R$ is continuous.
$\color{blue}{\text{If $U$ is open in $\overline {\Bbb R}$ then $U\cap \Bbb R$ is open in $\Bbb R$}}$ and $$f^{-1}U=A\cup B$$ where $$A=f^{-1}(U\cap \Bbb R)=g^{-1}(U\cap \Bbb R)$$ and $$B= f^{-1}(U \setminus \Bbb R).$$ Now $A$ is open in $D$ by continuity of $g,$ and $D$ is open in $\Bbb R,$ so $A$ is open in $\Bbb R.$ So $A$ is Borel in $\Bbb R.$
And $B=\emptyset$ or $B=\{0\}$ so $B$ is Borel in $\Bbb R.$
So $f^{-1}U=A\cup B$ is Borel in $\Bbb R.$
Why the blue part of the proof?
What result is being used?
$\color{blue}{\text{If $U$ is open in $\overline {\Bbb R}$ then $U\cap \Bbb R$ is open in $\Bbb R$}}$ it is because of the topology, this:
$$\tau_{A}=\{A\cap G: G~\text{is open in }X\}$$
when$$A\subset X$$
In the particular case of the exercise
As $\mathbb R\subset\mathbb{\overline {R}},$ the topology of $\mathbb R$ is defined as
$\tau_{\mathbb R}=\{\mathbb R\cap U: U~\text{is open in }\overline{\mathbb R}\}$