An objective function expresses how good or bad a solution is as a number, and an optimization algorithm searches for the solution that maximizes or minimizes it. In machine learning, a loss function that measures error plays this role, and in reinforcement learning the cumulative reward does.
AI safety research often discusses the problem that, when a specified objective function fails to capture everything people actually want, a system may optimize it in unintended ways.