JavaScript delay function

As you might know, JavaScript does not have a delay function by default. The only way to delay an action is the setTimeout() function, which does not help you if you want to pause your code entirely as it just continues to run the other code while only delaying a single action passed into the function. Therefor I came up with a rather confusing code snipped to new users. This code will delay the code executed after pressing a button by 400ms:


let delay = time => new Promise(res => setTimeout(res, time));
document.getElementById("button").onclick = async () => {
    await delay(400);
    //further code
}