Answer
See below.
Work Step by Step
The composition $(g\circ f )(x)$ is defined as $g[f(x)]$.
First, we must be able to compute f(x), so the domain of $g\circ f $ will be a subset of the domain of f.
Secondly, the value f(x) must be in the domain of g, so that we can calculate the value of $g[f(x)].$
Domain = all x from the domain of f, for which f(x) is in the domain of g.
For example,
$f(x)=x^{2}-1$ is defined for all real numbers x.
$g(x)=\sqrt{x}$ is defined for nonnegative x.
$g\circ f $is defined only for those numbers x for which $f(x)\geq 0$,
that is, for which
$x^{2}-1\geq 0$
$x^{2}\geq 1$
$D=\{x\in \mathbb{R} | x\leq-1$ or $x\geq 1\}$
The order does matter. Take the functions from the above example.
$(g\circ f) (x)=\sqrt{f(x)}=\sqrt{x^{2}-1}$
(domain: see above)
$(f\circ g)(x)=f(g(x)=[g(x)]^{2}-1=(\sqrt{x})^{2}-1=x-1$,
(domain: all nonnegative x, as g must be defined)
These are different functions.
$(g\circ f) (-1)$ is defined, $\qquad (f\circ g)(-1)$ is not.
$(g\circ f) (3)=\sqrt{8}=2\sqrt{2}$, $\qquad (f\circ g)(3)=2$ .