If you look at kinetic energies in the two rounds they are very comparable. A 9mm is slightly faster the .40 cal is slightly heavier. If you double the weight of a bullet you double the energy. If you double the speed of a bullet you quadruple the energy. Because of these two factors they work out to be the same energy. The problem with 9mm is that if it's a FMJ it has a decent chance of over penetration, this means some of the bullets energy doesn't stay in the target. This over penetration issue is fixed by using hollowpoints or other expanding ammunition. The .40 cal is 10% wider then a 9mm so it has less chance of overpentration with a FMJ. If both calibres are using hollowpoints they will have a near identical amount of stopping power. Since both rounds have the same amount of stopping power the 9mm gets an edge of the what's "better" factor because it's cheaper to practice and an unpinned magazine holds more.
Now queue all the people that think bigger is better and completely ignore what science says on the subject.