Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
124
rated 0 times [  128] [ 4]  / answers: 1 / hits: 19315  / 7 Years ago, thu, march 23, 2017, 12:00:00

I want to check JavaScript Version in my web browser.



Is navigator Object return proper JavaScript version?



navigator.appVersion;  /*Is it correct?*/
navigator.appCodeName;
navigator.appName;


Is there any way to detect exact JavaScript Version from Browser console or anything else?


More From » browser

 Answers
5

Browsers don't give any real version, because they don't exactly support any one version. They support some (or most) features of some versions.



Any support declared for JavaScript 1.x is just a legacy hack for compatibility with Netscape.



Similarly, these navigator fields are useless on purpose. In the past they have been misused to block browsers so much, that the spec now recommends all browsers to lie and say they are Netscape 4.0.



On the web, in general, you should never check version of anything to decide whether it supports the features you need, because it's too easy to make an invalid assumption and break your code in some browser, including future ones you can't test now (e.g. a feature may not be related to the version you assume, or browsers may lie about versions they support in order to work around sites blocking them).



You should use feature detection instead.



You can detect presence of individual JavaScript features by running them and seeing if they work. If the new feature requires a new syntax, you can try running that syntax inside eval. See how it's done on: https://kangax.github.io/compat-table/es6/ (there's a (c) icon with detection code next to features when you expand the list).


[#58424] Tuesday, March 21, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arturo

Total Points: 331
Total Questions: 99
Total Answers: 92

Location: Austria
Member since Thu, Jan 7, 2021
3 Years ago
;