Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can IE interpret both JScript and JavaScript?

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 ?

like image 771
Raynos Avatar asked Jul 22 '11 13:07

Raynos


People also ask

Is JScript and JavaScript same?

A lot of people think that JScript and JavaScript are different but similar languages. That's not the case. They are just different names for the same language, and the reason the names are different was to get around trademark issues.

What do you call the counterpart of JavaScript for Microsoft or Windows Internet Explorer?

JScript is Microsoft's equivalent of JavaScript.


2 Answers

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.

like image 62
T.J. Crowder Avatar answered Sep 30 '22 02:09

T.J. Crowder


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.

like image 23
lonesomeday Avatar answered Sep 30 '22 02:09

lonesomeday