Why Squared and divide by 2

In the equations for cost function, why the difference is squared and why it is divided by 2?

J = 1/2m sum(f(x) - y^)**2;

Its not very clear why it is squared and why it is divided by 2.

Please see these links:

  1. Link 1
  2. Link 2
1 Like

ok. thanks