How do I check the JavaScript version in a web browser?

I want to check JavaScript Version

in my web browser.

Is the navigator

object to return the correct JavaScript version?

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

      

Is there a way to detect the exact JavaScript Version

one Browser console

or something else?

+3


source to share


1 answer


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

Any support announced for "JavaScript 1.x" is just a deprecated Netscape compatibility hack .

Likewise, these fields are navigator

useless for purposes. In the past they were misused to block browsers, so the spec now recommends all browsers to lie and say they are Netscape 4.0 .



On the web, in general, you should never check the version of something to decide if it supports the features you want, because it's too easy to make an invalid assumption and break your code in any browser, including in the future, t test now (for example, the function may not be related to the version you are guessing, or browsers may lie about the supported versions to get around the blocks blocking them).

Function detection should be used instead .

You can detect the presence of individual JavaScript functions by running them and seeing if they work. If a new function requires a new syntax, you can try running that syntax internally eval

. See how it's done: https://kangax.github.io/compat-table/es6/ (there is an icon (c)

with a detection code next to the functions when expanding the list).

+4


source







All Articles