7

The window.setTimeout reference for IE states that setTimeout has an optional third parameter defining the language.

The possible languages are JScript, VBScript and JavaScript.

I already know IE can parse VBScript but

How does IE parse JavaScript differently from JScript?

Personally I thought the dialect of EcmaScript that IE parsers and runs was called JScript.

[Edit]

As mentioned by people it appears that Microsoft labels their ES3 engine as "JScript" and their ES5 engine as "JavaScript". The ES5 engine is in IE9.

Can we use their ES3 engine in IE9 by passing in "JScript" to setTimeout ?

Raynos
  • 166,823
  • 56
  • 351
  • 396
  • This question strikes me as being equivalent to asking whether Chrome can run 'V8 Scripts' but maybe I'm just confused by Microsoft's oddball terminology – dtanders Jul 22 '11 at 14:02
  • @dtanders I interpret JavaScript as the Mozilla implementation of the ES engine. There might have been a chance that IE secretly has an extra interpreter hidden in it. – Raynos Jul 22 '11 at 14:06
  • @dtanders: If you look at the MSDN link, it really does list "JScript" and "JavaScript" separately, and nowhere on the page does it say they're synonyms (which is just par for the course with MSDN documentation, in my experience; spotty doesn't half say it). – T.J. Crowder Jul 22 '11 at 14:21

6 Answers6

6

Personally I thought the dialect of EcmaScript that IE parsers and runs was called JScript.

It is. The "JScript" and "JavaScript" values for the third parameter are just synonyms. I can't find a reference for it, but you can be quite certain IE doesn't have two separate interpreters lying around, one that has JScript-isms and one that doesn't.

And here's the proof: If you run this in IE9 (live copy):

HTML:

<input type='button' id='btnJScript' value='JScript'>
<input type='button' id='btnJavaScript' value='JavaScript'>

JavaScript:

window.onload = function() {

  document.getElementById('btnJScript').onclick = function() {
    testIt("JScript");
  };
  document.getElementById('btnJavaScript').onclick = function() {
    testIt("JavaScript");
  };

  function testIt(lang) {
    var s = "var a = [1, 2, ]; display(a.length);";
    display("Calling <code>setTimeout</code> with <code>'" +
            s + "', 0, '" + lang + "'</code>");
    setTimeout(s, 0,lang);
  }
};

function display(msg) {
  var p = document.createElement('p');
  p.innerHTML = msg;
  document.body.appendChild(p);
}

In both cases, you get the output "2" displayed by the eval'd setTimeout string. But in JScript, even the most recent version in IE8, that trailing comma would mean the array had three entries, not two. Details on that here. Thus, IE9 is using its latest interpreter in both cases, not downshifting to "JScript" in some way if you pass "JScript" as the third parameter.

Update: And similarly (I just fired up my IE8 box), if you run this on IE8 you get "3" in both cases.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • I'd be great if older versions happened to have a full interpreter of JavaScript lying around as well as JScript though. That'd be the best. – Raynos Jul 22 '11 at 14:00
  • As far as IE is concerned, they're the same thing. – EricLaw Jul 22 '11 at 14:18
  • ps: this version (http://jsbin.com/idazuh/4) shows that EcmaScript is another synonym for Javascript, in the `setTimeout()` fn. Also, it shows that FredScript is not a legal name for a language. – Cheeso Sep 15 '11 at 16:00
3

From this MSDN page, you can see that JScript is Microsoft's name for its implementation of ECMAScript 3, whereas JavaScript is its name for the implementation of ECMAScript 5 that appears in IE9.

lonesomeday
  • 233,373
  • 50
  • 316
  • 318
  • Does mean that in IE9 I can run a snippet of JScript code by calling `window.setTimeout("var Run_AS_JScript = 42", 0, "JScript")` ? – Raynos Jul 22 '11 at 13:57
  • This answer is not correct, or at the least, is misleading. The MSDN page does not make the statement that the string "Javascript" refers to the IE9/ES5 implementation. It merely provides a link to the doc for Javascript-in-IE9, which is an implementation of ES5. It is more accurate to say: *in IE9, 'Javascript' refers to ES5.* You can also use the string 'Javascript' in IE8, and it does not use the ES5 implementation. That may be obvious to some, but it is worth clarifying. – Cheeso Sep 15 '11 at 15:46
  • Also: Though MS has not documented it, we can safely suppose that the string used in the language attr for ` – Cheeso Sep 15 '11 at 15:47
2

I guess the best answer I could give, somebody else already did.

Well known, Mr. Resig in person: http://ejohn.org/blog/versions-of-javascript/

snippet

  • 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.

I guess IE9's JScript engine (Chakra) comes as close as possible to "Javascript". However, it supports many features of ES5. See "IE9 Javascript engine". So we probably could extend the above list with

  • IE9 supports JScript 9 (which is equivalent to ECMAScript 5, JavaScript 1.8.5)
jAndy
  • 231,737
  • 57
  • 305
  • 359
  • That's completely unrelated to the question isn't it ;) To clarify. I know the difference between JScript and JavaScript. What are the differences between passing _those values_ into `setTimeout` – Raynos Jul 22 '11 at 13:55
  • @Raynos: 'completely unrelated', are you kidding ? – jAndy Jul 22 '11 at 14:04
  • @jAndy It's not unrelated but it doesn't answer my question. – Raynos Jul 22 '11 at 14:07
  • @jAndy JScript 7 & 8 are JScript.NET. IE9 uses JScript 9. – Raynos Jul 22 '11 at 14:20
  • @Raynos: didn't know that. can you give me the source of that please, pretty interested. – jAndy Jul 22 '11 at 14:27
  • @jAndy [Wikipedia article](http://en.wikipedia.org/wiki/JScript). I cant find a direct reference, but Microsoft does refer to versions of JScript.NET as JScript 7, 8 and 10. Logically I would assume that JScript 9 is indeed used in IE9 – Raynos Jul 22 '11 at 14:37
1

You can safely think that JScript is the same as JavaScript and you won't bump into any problems.

http://en.wikipedia.org/wiki/JScript#Comparison_to_JavaScript

Emil Ivanov
  • 37,300
  • 12
  • 75
  • 90
1

JScript and Javascript are the same things in IE. JScript was renamed to JavaScript in IE9 because of more standard (or better, more interoperable) implementation.

duri
  • 14,991
  • 3
  • 44
  • 49
1

The manual page you've referenced states that sLanguage is a parameter which can take the values VBScript, JScript, or Javascript.

It isn't that JScript is different from Javascript, it's just that both are valid names for the same language, they need to support both names.

JScript was Microsoft's name for their reverse-engineered clone of Javascript. The languages have now been merged by the standardisation work of the ECMA resulting in EcmaScript, although it is still generally referred to as Javascript.

But Microsoft needs to support both names because they want to retain compatiblity with old code written for ancient versions of IE which still uses the old JScript name.

Spudley
  • 166,037
  • 39
  • 233
  • 307