Trying your code in a regular browser show that it works as expected - jsfiddle.
Is it possible to override the implementation of native trim() function in JavaScript?
Yes it is possible but it is considered a bad practice.
I'll show how to do that because I think the code has it overridden already.
Here is how to do it:
String.prototype.trim = x => console.log('trim override');
'olá'.trim(); // trim override
What could be the reasons for this behavior?
Unless it's run in an unexpected environment it is most likely that the original author has trim
overridden to something that is different from native implementation. I would suggest you try to paste the polyfill with original implementation in to the console and checking if running it with that will fix the issue.
Here is the polyfill:
String.prototype.trim = function () {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
};
console.log('olá'.trim());
If the output of this code gives you the correct result (not trimming á
) you found the issue.