Differencebetween JavaScript and Ecmascript

What is the difference between JavaScript and ECMAScript?

I think a little history lesson is due.

JavaScript was originally named Mocha and changed to Livescript but ultimately became JavaScript.

It's important to note that JavaScript came before ECMAscript and the history will tell you why.

To start from the beginning, JavaScript derived its name from Java and initially Brendan Eich (the creator of JS) was asked to develop a language that resembled Java for the web for Netscape.

Eich, however decided that Java was too complicated with all its rules and so set out to create a simpler language that even a beginner could code in. This is evident in such things like the relaxing of the need to have a semicolon.

After the language was complete, the marketing team of Netscape requested Sun to allow them to name it JavaScript as a marketing stunt and hence why most people who have never used JavaScript think it's related to Java.

About a year or two after JavaScript's release in the browser, Microsoft's IE took the language and started making its own implementations such as JScript. At the same time, IE was dominating the market and not long after Netscape had to shut its project.

Before Netscape went down, they decided to start a standard that would guide the path of JavaScript, named ECMAScript.

ECMAScript had a few releases and in 1999 they released their last version (ECMAScript 3) before they went into hibernation for the next 10 years. During this 10 years, Microsoft dominated the scenes but at the same time they weren't improving their product and hence Firefox was born (led by Eich) and a whole heap of other browsers such as Chrome, Opera.

ECMAScript released its 5th Edition in 2009 (the 4th edition was abandoned) with features such as strict mode. Since then, ECMAScript has gained a lot of momentum and is scheduled to release its 6th Edition in a few months from now with the biggest changes its had thus far.

You can use a list of features for ECMAScript 6 here http://kangax.github.io/es5-compat-table/es6/ and also the browser support. You can even start writing Ecmascript 6 like you do with CoffeeScript and use a compiler to compile down to Ecmascript 5.

Whether ECMAScript is the language and JavaScript is a dialect is arguable, but not important. If you continue to think like this it might confuse you. There is no compiler out there that would run ECMAScript, and I believe JavaScript is considered the Language which implements a standard called ECMAScript.

There are also other noticeable languages that implement ECMAScript such as ActionScript (used for Flash)

What's the difference between JavaScript, JScript & ECMAScript?

Javascript is the original name when the language was developed by Netscape.

JScript is Microsoft's name of their own implementation.

ECMAScript is the name of the language standard developed by ECMA, from the original Javascript implementation.

So, it's just one language, with different implementations.

The implementations of Javascript and JScript differ somewhat in what they support, but each version supports what's in the corresponding version of the ECMAScript standard. Generally you just use what's supported a few versions back, so that it works in all the browsers that are still in use.

One reference is the Mozilla Developer Network, as Mozilla is the current developer of Javascript. For each method and property you can find which version it is supported in.

JScript is documented at the Microsoft Developer Network, and has similar information about support. (Note that all Microsoft documentation is there, not only JScript, so for example you would need to search for "jscript array" rather than just "array".)

Using a library like jQuery is useful to avoid dealing with some of the compatibility problems between browsers.

What is the difference between Javascript and ECMA script?

ECMAScript is a standard. JavaScript is an implementation of that standard (edition 3 of that standard to be more exact).

Other implementations of ECMAScript are ActionScript and JScript.

Also note that there isn't one JavaScript. Each JavaScript engine may implement its own version of the language as long as it meets the ECMAScript requirements. This means that browsers (JS engines) may have additional functionality, but they all must have the base ECMAScript functionality.

And now, to answer your question, according to RFC 4329, if the media type is set to application/ecmascript, rather than application/javascript, it must adhere to a stricter standard.

This document defines equivalent
processing requirements for the types
text/javascript, text/ecmascript, and
application/javascript. Use of and
support for the media type
application/ecmascript is considerably
less widespread than for other media
types defined in this document. Using
that to its advantage, this document
defines stricter processing rules for
this type to foster more interoperable
processing.

What's the difference between JavaScript and JScript?

Just different names for what is really ECMAScript. John Resig has a good explanation.

Here's the full version breakdown:

  • IE 6-7 support JScript 5 (which is equivalent to ECMAScript 3, JavaScript 1.5)
  • IE 8 supports JScript 6 (which is equivalent to ECMAScript 3, JavaScript 1.5 - more bug fixes over JScript 5)
  • Firefox 1.0 supports JavaScript 1.5 (ECMAScript 3 equivalent)
  • Firefox 1.5 supports JavaScript 1.6 (1.5 + Array Extras + E4X + misc.)
  • Firefox 2.0 supports JavaScript 1.7 (1.6 + Generator + Iterators + let + misc.)
  • Firefox 3.0 supports JavaScript 1.8 (1.7 + Generator Expressions + Expression Closures + misc.)
  • The next version of Firefox will support JavaScript 1.9 (1.8 + To be determined)
  • Opera supports a language that is equivalent to ECMAScript 3 + Getters and Setters + misc.
  • Safari supports a language that is equivalent to ECMAScript 3 + Getters and Setters + misc.

What is ECMAScript?

JavaScript is a subset of ECMAScript. JavaScript is basically ECMAScript at its core but builds upon it. Languages such as ActionScript, JavaScript, JScript all use ECMAScript as its core. As a comparison, AS/JS/JScript are 3 different cars, but they all use the same engine... each of their exteriors is different though, and there have been several modifications done to each to make it unique.

The history is, Brendan Eich created Mocha which became LiveScript, and later JavaScript. Netscape presented JavaScript to Ecma International, which develops standards and it was renamed to ECMA-262 aka ECMAScript.

It's important to note that Brendan Eich's "JavaScript" is not the same JavaScript that is a dialect of ECMAScript. He built the core language which was renamed to ECMAScript, which differs from the JavaScript which browser-vendors implement nowadays.

http://en.wikipedia.org/wiki/ECMAScript

Difference between ECMAScript6 and JavaScript

Javascript has had many names over the years and it is really just an implementation of ECMAscript.

It is a great idea to learn ES6 especially if you are doing any kind of web development.

Arrow functions and constants were introduced in ES6 and not everything that supports es5 supports es6 functionality. See this for an exhaustive list

So should you learn JS or start learning ES6? Either/both will serve you well. Personally I think the new features in ES6 may not be fully graspable until you learn the basic tenets of JS and you understand WHY they were introduced in ES6

What are the functional differences between JScript, JavaScript, and ECMA Script?

A implementation of the EMCAScript standard is more than code that brings the specification rules to life. The ECMAScript standard is deliberately incomplete:

Each Web browser and server that supports ECMAScript supplies its own host environment, completing the ECMAScript execution environment.

An ECMAScript implementation must supply a "host environment". In the case of a Web browser, that host environment includes DOM manipulation APIs and other APIs specified by the W3C and WHATWG. The behaviors of (indeed, the existence of) these APIs are not specified by ECMAScript.

Objects used to complete the "host environment" of an implementation are called "host objects". Host objects are not bound to follow normal object rules: they may throw errors for property access that would be valid on a native (non-host) object, or they might allow certain actions that would be natively disallowed.

JScript and JavaScript might implement their DOM APIs differently. Which implementation is "correct" on some particular point is not a matter of ECMAScript compliance, but rather a matter of compliance with W3C standards. Even if a DOM object seems to exhibit some behavior that runs contrary to "normal" ECMAScript behaviors (like your instanceof error example), it's still legal ECMAScript according to section 8.6.2:

Host objects may support these internal properties with any implementation-dependent behaviour as long as it is consistent with the specific host object restrictions stated in this document.

"Internal properties" here include logical operations like "getting the value of an object's property by name", codified as [[Get]]. A host object's custom [[Get]] implementation might throw an error, or ignore a previously-set property.

API differences are distinct from actual language differences. A language difference suggests a difference either in supported lexical grammar or in the behavior of native (non-host) objects. Some differences in actual language include:

  • JScript allows for cc_on comments that cause conditional compilation
  • Mozilla's JavaScript supports the yield keyword, and generators, and a bunch of other stuff that is not in the ES5 spec (but likely will be in ES6)
  • All browsers support function declarations in blocks, which is not legal ECMAScript syntax:

    function foo() {
    bar();

    if(condition) {
    function bar() { } // this is not legal
    }
    }

    Browsers that support this (i.e., all of 'em) are extending the ECMAScript language. Also, JScript will hoist bar in that example, while Mozilla's JavaScript will not. This is because the two browsers have extended the ECMAScript language in incompatible ways.

Why didn't Chrome create its own implementation of ECMAScript?

Why didn't Chrome create its own implementation of ECMAScript?

Chrome did create their own implementation of ECMAScript. The engine that ran their implementation of ECMAScript was and still is called V8 and is still in use today. In fact, it's now used by Chrome, Edge and Node.js (and others).

The public at the time didn't really know the phrase ECMAScript - they mostly just new about Javascript from Firefox and perhaps knew about JScript in IE. When Javascript was taken to a standard's body, they decided they wanted a name that had no trademark affiliation at all. In the words of Brendan Eich (the inventor of the language), the term "ECMAScript" chosen as clearly no trademark association at all and ugly enough that nobody would ever actually use the term in a user-facing product.

ECMAScript was not and still is not something John Q Public would know about (if not a developer). People knew of "Javascript" from the original Netscape days and currently at the time in Firefox/Mozilla. Some people knew that Microsoft's competing implementation that was similar (but not identical) was called JScript. Though even people developing largely for IE at the time would refer to Javascript as the language they were writing.

So, when Google developed their own new implementation of ECMAScript, they referred to it to the public as Javascript. That was just a name used to describe their implementation. That name meant NOTHING at all about its heritage. The V8 Javascript engine was entirely new, not a spin-off from something else.

To summarize, V8 is designed to be ECMAScript compatible and is known to the public in Chrome as a Javascript implementation.


In a note of history, "Javascript" was originally developed at Netscape. "Java" was originally developed at Sun Microsystems. Somehow in the relationship between Netscape and Sun Microsystems, Netscape was allowed to use the term "Javascript", but Sun actually owned the trademark on it. Eventually, the Netscape browser was spun out into the Mozilla foundation and Sun was acquired by Oracle. So, yes Oracle owns the trademark to the term "Javascript", but many are allowed to use it to describe their implementations of ECMAScript. Other companies, at various times, have preferred to stay completely away from any possible trademark issues and that's why others have use JScript, ActionScript, etc... to name their implementations.

You would need a trademark lawyer to go deeper into the legal issues around using the term Javascript.

When Mozilla spun out of AOL/Netscape as an independent company, they had a few firedrills around whether they could continue to use the term "Javascript" in their code and user interface. Some of those are documented in their bug system. I don't know the precise legal dealings that decided it all, but suffice it to say that they are still using the term "Javascript" many, many years later. Sun Microsystems wasn't bothered by that at the time and even a more litigious Oracle who now owns the trademark (by way of its acquisition of Sun) has not tried to stop its use at Mozilla or other places.


Keep in mind that V8 in Chrome implements a language to the ECMAScript standard. Chrome extends ECMAScript as do all browsers by adding their own global objects to the environment such as the window object in the browser. Those global objects in the browser are standardized in different standards efforts that have to do with browsers, not with the actual ECMAScript language.

type=text/ecmascript vs type=text/javascript

TL;DR Just omit the type tag, if you don't care about old browsers.

ECMAScript is a language specification standardized by ECMA International as ECMA-262 and ISO/IEC 16262. JavaScript is a programming language that implements this specification. ECMAScript exists in several editions. The latest edition is the 6th (in 2016), but most JavaScript implementations are only 5th edition compliant so far.

Besides ECMAScript common JavaScript implementations usually add more functionality, which might be standardized by other institutions (like the W3C) or might be proprietary (aka "browser-specific") features of the specific implementation. So you could say, that ECMAScript represents a subset of JavaScript.

However, the MIME types for JavaScript code are defined in the RFC 4329 document, which states that text/javascript and text/ecmascript are both obsolete and should be replaced by application/javascript and application/ecmascript:

Use of the "text" top-level type for this kind of content is known to
be problematic. This document thus defines text/javascript and text/
ecmascript but marks them as "obsolete".

The RFC defines stricter processing rules for the application/ecmascript than for application/javascript, but this refers to the handling of MIME-type parameters and the character encoding and not to the interpretation of the code itself:

In the cited case, implementations of the types text/javascript, text/ecmascript, and application/javascript SHOULD and implementations of the type application/ecmascript MUST implement the requirements defined in this section: [...]

For the application/ecmascript media type, implementations MUST NOT process content labeled with a "version" parameter as if no such parameter had been specified; [...]

The following error processing behavior is RECOMMENDED for the media types text/javascript, text/ecmascript, and application/javascript, and REQUIRED for the media type application/ecmascript.

Apart from the RFCs, there is also the HTML5-Standard by the W3C: Older versions of it say, that the default value for an empty type attribute is application/javascript, but newer versions don't mention any specific MIME-type anymore. Instead they define any script tag with no type or a MIME-type as a so-called "classic script":

Omitting the attribute, setting it to the empty string, or setting it to a JavaScript MIME type essence match, means that the script is a classic script, to be interpreted according to the JavaScript Script top-level production. Classic scripts are affected by the async and defer attributes, but only when the src attribute is set. Authors should omit the type attribute instead of redundantly setting it.

In general I would omit the type attribute (as recommended by the HTML5-Standard) or use type="text/javascript", if you have to support older browsers. A HTTP-Server should serve JavaScript code as application/javascript.

What is the difference between .js and .mjs files?

It indicates an ES6 module file.


Node.js's original module system is CommonJs (which uses require and module.exports).

Since Node.js was created, the ECMAScript module system (which uses import and export) has become standard and Node.js has added support for it.

Node.js will treat .cjs files as CommonJS modules and .mjs files as ECMAScript modules. It will treat .js files as whatever the default module system for the project is (which is CommonJS unless package.json says "type": "module",).

See also: Differences between ES6 module system and CommonJs



Related Topics



Leave a reply



Submit