1

There are functions and methods in my javascript code base that need to have assert statements to check for invalid arguments passed in. But these assertion statements should be stripped away when in production.

How are these assertion statements written in modern ES6 in development and how are they stripped away in production?

  • Not exactly what you're looking for, but if it were me, I'd use TypeScript, which requires the proper type(s) be passed, without any overhead after it gets transpiled to JS – CertainPerformance Aug 06 '22 at 01:44
  • But what if you need to also assert for range of values? TypeScript isn't able to do that. – Bear Bile Farming is Torture Aug 06 '22 at 01:46
  • Does this answer your question? [remove asserts from javascript code for production version](https://stackoverflow.com/questions/20372198/remove-asserts-from-javascript-code-for-production-version) – Ouroborus Aug 06 '22 at 02:20
  • 1
    "*How are these assertion statements written in modern ES6 in development?*" - as function calls. "*and how are they stripped away in production?*" - using your favourite build tool. From sed/awk to a babel plugin there's probably lots of solutions. – Bergi Aug 06 '22 at 04:16

0 Answers0