What is the domain of $f^2$ if $f(x)=\sqrt{x+2}$ Now, $f(x)$ is defined for all values of $x$ for which $x+2 \geq 0$

$x+2 \geq 0 \implies x \geq -2$
So, $\mathrm{Domain}(f)=[-2,\infty)$ which means $f : [-2,\infty) \longrightarrow \Bbb R$
$f^2(x) = \Big (f(x) \Big )^2=(\sqrt{x+2})^2=x+2$
So, $f^2$ is defined for all values of $x$, right? So, shouldn't $f^2:\Bbb R \longrightarrow \Bbb R$ ?
According to my textbook, $f^2:[-2,\infty) \longrightarrow \Bbb R$
But if we take something outside of $[-2,\infty)$, for example $-5$ and put it in $f^2(x)$, we get:

$f^2(-5) = \Big (f(-5) \Big )^2=(\sqrt{-5+2})^2=(\sqrt {-3})^2=(-3) \in \Bbb R$
Doesn't this mean that $f^2$ is defined for values outside the domain of $f$ as well? So, am I right or is the book right? If the book's right, where am I wrong?
Thanks!

You have written $f^2(-5)=(f(-5))^2$. It is correct, however, look at the inside function of the RHS. It is $f(-5)$. Can you define $f(-5)$? No. That means $f^2(-5)$ is undefined. Similarly $f^2$ is undefined for any $x<-2$. So, your book is correct.
