можно так)
const input = document.getElementById('password');
const btn = document.getElementById('showPassword');
btn.addEventListener('click', (e) => {
e.preventDefault();
switch (input.type) {
case 'password': return input.type = 'text';
case 'text': return input.type = 'password';
}
})