Browser detection
An ideal way to develop a system is to perform capability testing first. We should get the information if the environment where the system will run is capable of doing things we want to do. But that hardly happens, and at the same time it is not always possible, be it any reason—unforeseen issues, changing requirements, insufficient time, and many more. That's one big reason we need browser detection and perform quick fixes.
User agent sniffing
Browser detection is mostly done by checking user agent string, which is not completely reliable because user agent string can be spoofed. A developer is encouraged to use feature detection over browser detection. You should not rely on browser detection to assume that a feature will be available, instead perform feature detection and write code accordingly.
Mostly, browsers have been sharing similar user agent strings and hence the history of user agent strings have been very dramatic. You would find more details about this at http...