I think the simplest solution is:
window.scrollTo({top: 0, behavior: 'smooth'});
If you wanted instant scrolling then just use:
window.scrollTo({top: 0});
Can be used as a function:
// Scroll To Top
function scrollToTop() {
window.scrollTo({top: 0, behavior: 'smooth'});
}
Or as an onclick handler:
<button onclick='window.scrollTo({top: 0, behavior: "smooth"});'>Scroll to Top</button>