A function gives each input exactly one output. The range consists of the outputs actually achieved. Surjectivity means all of the declared codomain is reached.
If \(f(x_1)=f(x_2)\) forces \(x_1=x_2\), the function is one-to-one. A graph then meets each horizontal line at most once.
In \((f\circ g)(x)=f(g(x))\) first apply \(g\). The input must be in the domain of \(g\) and the intermediate value in the domain of \(f\).