Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default javascript version in browsers

Tags:

javascript

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.

like image 804
Dmitriy Nesteryuk Avatar asked May 23 '26 21:05

Dmitriy Nesteryuk


2 Answers

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>
like image 166
scunliffe Avatar answered May 26 '26 10:05

scunliffe


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:

  • IE has JScript
  • Chrome has V8
  • WebKit has JavaScriptCore
  • etc.

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.

like image 38
Christian C. Salvadó Avatar answered May 26 '26 09:05

Christian C. Salvadó



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!