9mm has lower recoil, so it is easier to shoot faster, cheaper to shoot, and has a higher capacity. Most people will prefer that, and when shooting at a human, without body armor, without barriers, you would be hard pressed to notice any terminal difference between 9mm and .40.
However the 40 has more power on paper, can shoot heavier bullets, and penetrate further through soft targets and barriers. It's a great law enforcement round, because many of their shootings occur in and around vehicles.
The 40 has more recoil, less capacity, but you have a slight edge in power, mainly in the form of penetration.
I think they both have their place. 9mm is hard to beat for EDC and civilian self defense, it is certainly lethal with a good JHP, and won't zip through your target with as much force as a .40 could.
.40 has a heavier bullet, with more powder, more mass, more kinetic energy, you feel the recoil to prove that being true. The increased penetration is physics, it can not be denied, but it's really not necessary.
Some argue that the bullet diameter is an advantage. There's not a huge difference in .40 and .355, but there is a difference, they both expand to a greater diameter, but the .40 expands more, it's technically more lethal, but dead is dead. If there is a BG that's been shot by 9mm, and a BG shot by .40, the one shot by .40 is not more dead, and it doesn't matter what caliber you're shooting if you can't get shots in center of mass. All handgun rounds are limited, and if you want to stop someone in their tracks it would be wise to hit them several times in the center of their chest. If you can't do that with 9mm, you can't do it with .40, but if you can do it with .40 you can do it faster with 9mm.