Why It's Dangerous (With One Exception)
JavaScript allows adding methods to built-in prototypes like Array.prototype or String.prototype. This is almost always a bad idea.
// BAD PRACTICE:
String.prototype.shout = function() {
return this.toUpperCase() + '!!!';
};
'hello'.shout(); // 'HELLO!!!'
Why This Is Dangerous
- Naming Conflicts: Two libraries adding the same method name will silently overwrite each other.
- Future Standards: If JavaScript officially adds the same method name later, your code breaks.
- Global Pollution: Every object of that type in your entire app gets the method unexpectedly.
The One Acceptable Exception: Polyfills
Implementing a newer standard feature for older browsers that don't support it natively.
Caution
This is called " prototype pollution " — one of the most notorious sources of subtle, hard-to-debug bugs in JS libraries.