How to detect the ECMAScript version?

avatar
by Virender
August 27, 2021

<html>
   <head>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <title>Detect ECMA Version</title>
      <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
      <script>
	  "use strict";
	  
    var getECMAVersion = function() {
		var rv ="";
		
        return rv = null, "function" == typeof RegExp && (rv = {
            edition: 3,
            date_published: "1999-12"
        }), "function" == typeof Array.isArray && (rv = {
            edition: 5,
            date_published: "2009-12"
        }), "function" != typeof Array.find && "function" != typeof Array.findIndex || (rv = {
            edition: 6,
            date_published: "2015-06",
            name: "ECMAScript 2015",
            name_code: "ES2015"
        }), "function" == typeof Array.prototype.includes && (rv = {
            edition: 7,
            date_published: "2016-06",
            name: "ECMAScript 2016",
            name_code: "ES2016"
        }), "function" == typeof Object.entries && (rv = {
            edition: 8,
            date_published: "2017-06",
            name: "ECMAScript 2017",
            name_code: "ES2017"
        }), "undefined" != typeof Promise && "function" == typeof Promise.prototype.finally && (rv = {
            edition: 9,
            date_published: "2018-06",
            name: "ECMAScript 2018",
            name_code: "ES2018"
        }), "function" != typeof Object.fromEntries && "function" != typeof String.prototype.trimStart || (rv = {
            edition: 10,
            date_published: "2019-06",
            name: "ECMAScript 2019",
            name_code: "ES2019"
        }), "function" == typeof BigInt && (rv = {
            edition: 11,
            date_published: "2020-06",
            name: "ECMAScript 2020",
            name_code: "ES2020"
        }), rv
    }

    $(document).ready(function() {
        var ecma = getECMAVersion();

        if (typeof ecma !== "undefined") {

            var ecmaversion = "";

            if (ecma.edition) {
                ecmaversion = ecmaversion + "<div>ECMAScript Edition: " + ecma.edition+ "</div>";
            }

            if (ecma.name) {
                ecmaversion = ecmaversion + "<div>Name: " + ecma.name + "</div>";
            }

            if (ecma.date_published) {
                ecmaversion = ecmaversion + "<div>Released: " + ecma.date_published + "</div>";
            }

           $("#ecma-verion").html(ecmaversion);
        }
    });
</script>
   </head>
   <body>
      <div class="value" id="ecma-verion"></div>
   </body>
</html>
Share:

Tags:

Related posts