It has a gun because pilots don't feel comfortable without a gun. It makes no sense, but fifty years ago the USAF jumped the gun a little bit on air-to-air missiles, and whenever someone points out the gun is a stupid thing to include on a modern strike fighter people bring up this fifty year old problem.
The A version of the F-35 has three seconds worth of gun ammo. It would only be two seconds, but there's some lag between the trigger pull and the gun being fully spun up.
For CAS these planes are simply not good for. For that role A-10 or Super Tucano like cheaper planes are needed, because those planes are more efficient for that role.
The A version of the F-35 has three seconds worth of gun ammo. It would only be two seconds, but there's some lag between the trigger pull and the gun being fully spun up.