Following code changes property printed (when accessed through javaScript) by browser console and not the actual Use-Agent string sent with the header.
This isn't possible from the page itself. The user agent string (as sent in the HTTP request headers) can only be changed via browser extension or browser configuration.