3

Which version of JavaScript do use browsers by default? I read a documentation about different versions of javascripts supported by Firefox (https://developer.mozilla.org/en/JavaScript). There are many interesting and useful things. Unfortunately, I am confused now which version might I use in the development.

1
  • You generally can't control the version; they use what they use. Taking advantage of browser-specific features is generally done by an approach called "feature detection." Commented Oct 14, 2010 at 17:39

3 Answers 3

4

Unfortunately knowing the actual version won't help you much due to missing/broken implementations.

You are better off to test for a method that you fear an older browser might not support etc.

e.g. if supporting IE5 and you want to be able to use the Array.push() method you could do something like:

if(typeof(Array.prototype.push) == 'undefined'){
  Array.prototype.push = function(item){
    var len = this.length;
    this[len] = item;
    return this.length;
  };
}

As for your actual script tags - do not include a language attribute with the version - its deprecated.

<script language="JavaScript1.2">...</script><!-- BAD -->

<script type="text/javascript">...</script><!-- GOOD -->

<script>...</script><!-- ALSO GOOD -->

If you are playing the XHTML game and thus need valid XML output, you'll want to wrap your script tag content as follows.

<script type="text/javascript">
  <![CDATA[
    //your code here...
  ]]>
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

Isn't there something special you need to do in order to use that weird "XML in Javascript" feature that Firefox supports? I can't remember whether that's in the "type" attribute or not.
If you are outputting XHTML then yes, you will need to escape the contents of your script tag with CDATA so that less-than and ampersand symbols don't break things. I'll update a code sample for this.
4

JavaScript (TM) is the implementation of the ECMAScript Standard, made by the Mozilla Corporation.

They have implemented a lot of non-standard features that you will only find in their implementations (SpiderMonkey, Rhino) you shouldn't get confused with their versioning.

Other browsers have their own implementation of the standard, for example:

JavaScript 1.5 conforms with the ECMAScript 3rd Edition Standard, subsequent versions, JS 1.6, 1.7, 1.8 and 1.9 introduce language features that are out of that standard edition, part of the new ECMAScript 5th Edition, and other specific features often called Mozilla Extensions.

Comments

2

You can pretty much use the ECMAScript 3rd edition standard which is almost fully implemented in all current browsers.

The spec is here: http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf

Also, check out this great Wikipedia article about JavaScript implementations in web-browsers: http://en.wikipedia.org/wiki/Comparison_of_layout_engines_(ECMAScript)

The new edition (ECMAScript 5th edition) will be implemented in IE9 and all modern browsers next year, but not older versions of IE.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.