The point is the kg of hydrocarbon is less able to release its 40MJ all at once because the oxygen which is spread out over 4000 times as much volume needs to get to it. The battery contains both ends of the reaction, but the hydrocarbon only contains one.
TnT or nitroglycerin is much more dangerous in spite of much lower energy density because the energy is all in the TnT.
Of course this isn't the only consideration (the fact that TnT releases nitrogen which suddenly wants to be much bigger is important, for example), but it is a reason to hesitate around such a battery and carefully consider whether you want to throw it around at 100km/h.