Usually the first sense to go when dying is smell since when you die you stop breathing and you need to be able to breathe to smell.
Then your senses such as touch, taste and sight go and then last your hearing goes unless you're already deaf before you die.
So if the person was able to hear before then the hearing of the person would be the last sense to go when that person dies.
That's why doctors say that the person is likely able to hear you as they're dying even though they may not be able to understand what you're saying to them.