Is Apple's Mail.app more secure over using webmail? I have heard that webmail services (even the one with E2EE) are prone to JavaScript based attacks, while native apps like Mail.app in macOS are secure against such attacks.

Is this true? Is it better to use Mail.app than using webmail?
In practice no Mail.app is not more secure.

The reason being that most mail providers also provide a webmail service e.g. Gmail, iCloud, Outlook.

So you have the risks of webmail as well as possibly other from Apple Mail. the attacks against Apple Mail are different.

Re Javascript attacks I use webmail and don't allow download of images and use web blockers to stop various Javascript from running. Mail.app will run Javascript (the message pane is in effect a web browser)

Now if you could find a mail provider that does not provide webmail access then there might be something in the original premise. However there will be other security issues and so you can't say one is more secure than the other.

In all cases turn javascript off if you can if you are worried about security. There is a good case for using text based mail user agents like pine, mutt, even emacs, however the mail might not be as friendly and as easy to use.

Remember security is relative. Nothing is 100% secure. You just have to choose how secure you need it to me. A CIA operative will have different needs to a normal member of the public.