The Navigator.userAgent read-only property returns the user agent string for the current browser.
This is a test I ran to see this function in action in my Google chrome’s browser.
I found an interesting point in the MDN docs:
Browser identification based on detecting the user agent string is unreliable and is not recommended, as the user agent string is user configurable. For example:
In Firefox, you can change the preference general.useragent.override in about:config. Some Firefox extensions do that; however, this only changes the HTTP header that gets sent and that is returned by navigator.userAgent. There might be other methods that utilize JavaScript code to identify the browser.
Opera 6+ allows users to set the browser identification string via a menu.