How to mask characters in a string such as mask few numbers in Phone number using JavaScript ?

Let’s write a simple JavaScript method to mask characters in a string.

What we are trying to achieve, mask a phone number such as +919895590552 to +919895******

function mask(mobile_number, maskCount){
  let nonMaskedNumber = mobile_number.slice(0, 0-maskCount);
  let maskChar = '*'.repeat(maskCount);
  return `${nonMaskedNumber}${maskChar}`
}

The above function does the job but it needs to be adjusted for certain edge cases.