0

I am playing with some newer features of JavaScript such as Array.forEach (v.1.6).

I understand that in live code we should use feature detection, as explained here: To tell Javascript version of your browser So, basically something like:

typeof Array.prototype.forEach == 'function'

However, is there some way (e.g. website) , that shows which version of JavaScript is supported by different browsers? I basically want to check if a given version is already widely adopted by browsers or not.

Somethin like this for JavaScript support would be exactly what I am looking for.

Community
  • 1
  • 1
Sebastian K
  • 6,235
  • 1
  • 43
  • 67
  • Something like this? http://kangax.github.com/es5-compat-table/ – Blender Feb 16 '13 at 23:23
  • 1
    Yeah, that one is pretty good, care to make it an answer? It basically tells me the array functions I was playing with have quite wide support already. – Sebastian K Feb 16 '13 at 23:27

2 Answers2

3

No, not really. You should do feature testing instead of which version of JS a browser supports for many of the new HTML5 features.

For some of the new features of ECMAScript 5 you can create or use third party shims that emulate the features and don't cause errors in older browsers. Not all features will work though for ECMAScript 5 but many will.

https://github.com/kriskowal/es5-shim

Paul Mendoza
  • 5,709
  • 12
  • 53
  • 82
  • This is good advice. Check whether the specific feature you want is available, not some version number. There are many good polyfills for ES5 features that you can optionally add in for missing features. – James A. Rosen Feb 16 '13 at 23:36
  • That is right. My question is more along the lines, if we support IE8, IE9, IE10, Latest Chrome, Firefox, and Safari, do I have to worry about feature detection and polyfills, or I can safely assume (array) functions I want to use will be available. – Sebastian K Feb 17 '13 at 00:00
  • definitely need feature detection for IE – charlietfl Feb 17 '13 at 00:13
  • @charlietfl Yeah, according to link from Blender, IE8 is pretty much the only popular browser not supporting extended array functions. – Sebastian K Feb 17 '13 at 01:01
1

I agree with the other comments that you should probably not check the javascript version as a way to make sure features you are using will work.

Recommended:

Not recommended:

However, to answer the question. Here is how you can check the version of javascript supported by the browser.

<script type="text/javascript">
    var version = 1.0;
</script>
<script language="Javascript1.1"> version = 1.1; </script>
<script language="Javascript1.2"> version = 1.2; </script>
<script language="Javascript1.3"> version = 1.3; </script>
<script language="Javascript1.4"> version = 1.4; </script>
<script language="Javascript1.5"> version = 1.5; </script>
<script language="Javascript1.6"> version = 1.6; </script>
<script language="Javascript1.7"> version = 1.7; </script>
<script language="Javascript1.8"> version = 1.8; </script>
<script language="Javascript1.9"> version = 1.9; </script>

<p id="version"></p>

<script>
document.getElementById("version").innerHTML = version;
</script>
Matt
  • 1,388
  • 15
  • 16