A cost function in a neural network is a function that computes the error and informs us how far the created neural network is from the expected output. That is, it quantifies how far it is from the correct output.
If you are aiming for a career in Machine learning, then check out the Machine learning course from Intellipaat, which helps you to gain practical exposure through its online training course and guided projects.
If you wish to know more then check out our YouTube video on Cost Function Machine Learning to get started.