Consider a function $f:\mathbb R\to\overline{\mathbb R}$ defined as $$f(x)=\begin{cases}\frac{1}{x}, x\neq 0\\ \infty, x=0 \end{cases}$$
Is $f$ Borel-measurable?
I followed the answer given here Prove $\phi(t)=1/t$ is Borel function. by martini
Let $a\in\mathbb R.$
For $a<0,$ \begin{align*} x \in f^{-1}([-\infty, a]) &\iff f(x) \le a \\ &\iff \frac 1x \le a\\ &\iff x \ge \frac 1a \&\ x < 0 \end{align*} Hence $f^{-1}([-\infty, a]) = [\frac 1a, 0)$, which is a Borel set.
For $a=0,$
\begin{align*} f^{-1}([-\infty,a])\\ &\iff f^{-1}([-\infty,a)\cup\{a\}\\ &\iff \frac 1x<a\cup\{a\}\\ \end{align*}
from here how to find the interval for $x$? like in the case $a<0$, $x$ was between certain values but in this case $\frac 1x<a\implies \frac 1a<x$ which can't be since $a=0$?
In the answer mentioned was $(-\infty, 0]$
Something similar happens in the case $a>0$.
For $a\in \mathbb{R}$.
You correctly proved that, for $a<0$, $$f^{-1}([-\infty, a]) = [\tfrac 1a, 0)$$
which is Borel.
For $a=0$, since: $ x \in f^{-1}([-\infty, 0]) \iff x<0$. (Details: Since $0$ is not in the image of $f$, we have: $ x \in f^{-1}([-\infty, 0]) \iff x \in f^{-1}([-\infty, 0))\iff \frac{1}{x}<0 \iff x<0$). So $$f^{-1}([-\infty, 0]) = (-\infty, 0)$$ which is Borel.
For $a>0$, we have that, for $x<0$, it is true that $\frac{1}{x}\le a$. On the other hand, we know that for $x>0$, $\frac{1}{x}\le a$ if and only if $x\ge \frac{1}{a}$. So we have: $$ f^{-1}([-\infty, a])= (-\infty, 0) \cup [\tfrac 1a, +\infty)$$ which is Borel.
Now, we need to inspect two other cases: $a=-\infty$ and $a = \infty$.
It is easy to see that
$$ f^{-1}([-\infty, -\infty])= \emptyset$$ which is Borel. And
$$ f^{-1}([-\infty, \infty])= \mathbb{R}$$ which is Borel.
So $f$ is Borel measurable.
Remark 1: Since the function $f$ is from $\mathbb R$ to $\overline{\mathbb R}$, to prove it is Borel measurable we need to prove that:
It can be proved that this condition is equivalent to
(Atention: $a \in \overline{\mathbb R}$, not just $a \in \mathbb R$)
Of course, we could also work with $a \in \mathbb R$ and explicitly check $f^{-1}(\{-\infty\} )$ and $f^{-1}(\{\infty\} )$ to ensure they are Borel set. Any way, to prove that $f$ is Borel measurable, we need to consider the extremes points of $\overline{\mathbb R}$.
Remark 2: Since $[-\infty, -\infty] = \{-\infty\}$, and since there is no $x \in \mathbb{R}$ such that $f(x)= -\infty$, we have: $$ f^{-1}([-\infty, -\infty])= \emptyset$$
Since $[-\infty, \infty]= \overline{\mathbb R}$ and, for all $x \in \mathbb{R}$, $f(x) \in \overline{\mathbb R}$, we have that
$$ \mathbb{R} \subseteq f^{-1}([-\infty, \infty])$$
But, since $\mathbb{R}$ is the domain of $f$, we also have
$$f^{-1}([-\infty, \infty]) \subseteq \mathbb{R}$$
So we conclude: $$f^{-1}([-\infty, \infty]) = \mathbb{R}$$