To factor the quadratic expression \( g^2 + 3g - 40 \), we need to find two numbers that multiply to \(-40\) (the constant term) and add up to \(3\) (the coefficient of the linear term).
The numbers that satisfy these conditions are \(8\) and \(-5\) because:
\[ 8 \times (-5) = -40 \quad \text{and} \quad 8 + (-5) = 3 \]
Now, we can factor the quadratic expression:
\[ g^2 + 3g - 40 = (g + 8)(g - 5) \]
Thus, the factored form of \( g^2 + 3g - 40 \) is:
\[ \boxed{(g + 8)(g - 5)} \]