For an understanding of the concept of function composition, see following example. "Every apple price is 5$, how many dozens of apples can be bought for x dollars?" call this, a function f(x). "If every dozen of apples bought, gets one free apple; then, how many free apples are got with n dozens bought?", call this function g(n).
Then gof(x), talks about "How many free apples can be got with money x$", got the idea. It uses both function concepts and composes them, to directly arrive at final answer from input. fog(x) is not defined because it does not make sense, got it.
These are "formalized" in math by saying that, the range of f should be the domain of g, for composition to be defined.