Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect ECMAscript version?

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.

like image 665
jacky Avatar asked Nov 19 '17 07:11

jacky


People also ask

What is the current ECMAScript standard?

This Standard defines the ECMAScript 2022 general-purpose programming language.

Is ES6 and ECMAScript same?

ES6 is also known as ECMAScript 2015 as it is released in 2015. Its class allows the developers to instantiate an object using the new operator, using an arrow function, in case it doesn't need to use the function keyword to define the function, also return keyword can be avoided to fetch the computer value.

What is the latest version of JavaScript 2022?

The JavaScript family is ever-evolving and is set to launch new JavaScript features in June 2022. The ES2022 will be the 13th edition of features after it was initially launched in 1997. The ES2022 features that reach the stage 4 verification are added to the JavaScript family.

What version of ECMAScript do browsers support?

ECMAScript 5 on IE is fully supported on 10-11, partially supported on 9-9, and not supported on 5.5-8 IE versions. ECMAScript 5 on Edge is fully supported on 12-103, partially supported on None of the versions, and not supported on below 12 Edge versions.


2 Answers

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 :(")
}
like image 71
Nandu Kalidindi Avatar answered Sep 28 '22 00:09

Nandu Kalidindi


I don't think that's possible because browsers normally don't implement all features of an ECMAScript version at once. That's why we have libraries like Modernizr and websites like Can I use ... to find out what features can be used.

You could still build a little test that determines how RegEx in the user's browser version behaves.

like image 36
Niklas Higi Avatar answered Sep 27 '22 22:09

Niklas Higi