What is the constant function, exactly?
Solution 1:
Both are constant, the difference is just the domain, that is, the values your function is allowed to take as input. It is constant in so far as the output is always the same no matter what the input is, and this value doesn't have to be $0$, it can be anything else as long as it's the only value the function can output.
Sure, in the function given by the teacher, $f(-2)$ will be undefined, but saying it like that is misleading. The value $-2$ is not part of the domain, $f$ can't accept $-2$ as input, it's not as if $f(-2)$ existed but had some weird undefined value, it just doesn't exist at all. So the function effectively only outputs one value, in this case it's $0$. I hope I'm making sense and not confusing you further.
EDIT (can't comment on other posts) : @Angel I think what they mean by "$f : \mathbb{Z} \rightarrow 0$ means $f(x) = 0$ not for all $x$" is "the value of $f$ isn't $0$ for all $x$ since there are values of $x$ (outside of the domain) where $f$ isn't defined and as such for which $f(x)$ isn't $0$". A confusion about what functions and domains are, and the teacher probably has an habit of writing $\forall x$ instead of $\forall x \in \mathbb{R}$ which might lead to further confusion about what "for all" means in general.
Solution 2:
A constant function is a function which is constant. That is $f(x)=c$ for all $x$ and some $c$. There is no reason to restrict this definition to the case where $c,x\in\mathbb{R}$ and $f:\mathbb{R}\to\mathbb{R}$.