5

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?

Sumon Sarker
  • 2,707
  • 1
  • 23
  • 36
  • 1
    Already asked here: http://stackoverflow.com/questions/4271566/how-do-i-know-which-version-of-javascript-im-using – exoslav Mar 23 '17 at 09:16
  • What are you planning to do once you've detected the version, whatever that means? –  Mar 23 '17 at 09:35
  • I want to show warning/alert to user, If some new features of latest Javascript version are not supported current(old) version Of Javascript in clients browser. @torazaburo – Sumon Sarker Mar 23 '17 at 09:40
  • And also want to know about `navigator.appVersion;` is returning exact version of Javascript or Not. @torazaburo – Sumon Sarker Mar 23 '17 at 09:43
  • Maybe this question is not 100% duplicate of that question you mentioned :( :( :( @torazaburo – Sumon Sarker Mar 23 '17 at 09:45
  • What is the user supposed to do when they see the warning? –  Mar 23 '17 at 11:14

1 Answers1

7

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).

willy wonka
  • 1,440
  • 1
  • 18
  • 31
Kornel
  • 97,764
  • 37
  • 219
  • 309
  • Thank you for your explanation! I updated my question. Please check. – Sumon Sarker Mar 23 '17 at 09:23
  • 2
    On Chromium `chrome://version/` give the name and version of the JS Engine (V8). Is there a way in Firefox to display SpiderMonker version (there is nothing in `about:support`)? – noraj Jul 01 '22 at 09:18