How do I delay a function for a short time after it gets called.

I’ve been working on a small melee system in a project I’ve been working on however there is the exploit that you can just mash the mouse button to destroy the enemy within a second, even if it requires 3 to 4 hits to destroy them.

what I need is for the function to be unusable for a short time after it gets called, and then reusable after a second or two.
I am programming in JavaScript, thank you for any support you can give.

You should learn about Coroutines for this type of problem