Short Answer It is convenient to know where the output lies. I can tell whether a function is real-valued or complex-valued with an appropriate use of the codomain. Long Answer Functions exist in many contexts; not just Calculus. In Linear Algebra, the functions of interest are linear transformations.
What is a codomain in a function?
A codomain of a function is any set containing the range of the function - it does not have to equal the range. For example the function y=x² has as a codomain the set of real numbers, which is a set containing the range (y≥0), but is not equal to the range.
How do you find the codomain?
The domain of a function is the set of all possible inputs for the function. For example, the domain of f(x)=x² is all real numbers, and the domain of g(x)=1/x is all real numbers except for x=0. We can also define special functions whose domains are more limited.