How to detect ECMAscript version?

jacky picture jacky · Nov 19, 2017 · Viewed 15.7k times · Source

I want to see what ECMAscript version I'm using in my browser(e.g,chrome 59) ,because there is some difference between ECMAscript3 and ECMAscript5 when dealing with something RegExp stuff.
I've found the relevant information about this,but I can't find a specific answer about how to detect the ECMAscript version.
Thank's in advanced.

Answer

Nandu Kalidindi picture Nandu Kalidindi · Nov 19, 2017

May be you can try to use some data structures that are specifically added in ES6 like Map, Set etc. This is to differentiate between ES5 and ES6 but you can look up for features that are added in ES5 which are not present in ES3 in your case?

try {
  var k = new Map();
  console.log("ES6 supported!!")
} catch(err) {
  console.log("ES6 not supported :(")
}

try {
  var k = new HashMap();
  console.log("ES100 supported!!")
} catch(err) {
  console.log("ES100 not supported :(")
}