The Advantages and Disadvantages of JavaScript
April 26, 2002
We've already seen some of the advantages of JavaScript, like cross-browser
support, validating data on the client, and being able to create more sophisticated
user interfaces.
JavaScript effects are also much faster to download than some other front-end technologies like Flash and Java applets.
In fact, unless you're writing a massive JavaScript application, it's quite
likely that no significant extra download time will be added to a page by using
JavaScript on it. Nor do users need to download a plugin before they can view
your JavaScript, as they would with Flash for example, they simply need a browser
that supports it – and, of course, most
modern browsers do.
Other advantages include the fact that you don't need any extra tools to write
JavaScript, any plain text or HTML editor will do, so there's no expensive development
software to buy. It's also an easy language to learn, and there's a thriving
and supportive online community of JavaScript developers and information resources.
The disadvantages of JavaScript, as with most web development, are almost
entirely related to browser compatibility.
While the advances in browser programmability we've seen over recent years
are, generally speaking, a good thing, if you don't implement them with care
you can create a lot of inconsistencies and broken pages quite unintentionally
using JavaScript. Code that works just great on IE4 might not work at all on
Netscape 4, what works in NN6 doesn’t always work in NN 4, and so on.
In essence, there are two main problems with JavaScript and browsers:
·
The different JavaScript versions in different
browsers.
·
Browser programmability: the HTML elements and
features of the browser that can be accessed through any scripting language.
(IE4 , for example, makes most of the page and HTML accessible to scripts, but
Navigator 4 limits what can be accessed and manipulated.)
JavaScript Version Differences between Browsers
The JavaScript language has gone through a number of versions,
right from the first release, JavaScript 1.0, to the latest version, JavaScript
1.5 (supported by Netscape browsers, currently Netscape 6.2). Microsoft calls
its own version of JavaScript JScript,
which began with JScript 1.0, and is currently at JScript 5.6, (supported by
IE 6).
While the names and numbers of the versions of JavaScript supported by Netscape
and Microsoft may differ, the languages themselves are broadly, but not entirely,
the same. And therein lies the problem: there are a significant number of small
and sometimes subtle differences that can catch you out.
This table lists the different versions and indicates where IE and Navigator
versions of JavaScript are roughly compatible:
|
Browser
|
NN3.0
|
NN4.0 - 4.05
|
NN4.06 - 4.76
|
NN6.0+
|
|
IE3.0
|
JavaScript 1.1
JScript 1.0
|
|
|
|
|
IE4.0
|
|
JavaScript 1.2
JScript 3.0
|
JavaScript 1.3
JScript 3.0
|
|
|
IE 5.0
|
|
|
|
JavaScript 1.5
JScript 5.0
|
|
IE 5.5
|
|
|
|
JavaScript 1.5
JScript 5.5
|
|
IE6.0
|
|
|
|
JavaScript 1.5
JScript 5.6
|
The table only gives a very rough approximation, and in those terms JavaScript
IE3 = NN3, IE4 = NN4 and IE5+ = NN6. An example of the small differences is
the try..catch clause, which is supported
in JavaScript by IE5+ and NN6+, but not in IE4 or NN4.
Although there are plenty of references you can use to look up such differences,
the only way of being absolutely sure that a page will work on different browsers
is to test it as widely as possible. Programs such as VirtualPC from www.connectix.com
allows you to install and run multiple operating systems with different browsers
from one host operating system.
What is JavaScript?
Practical JavaScript for the Usable Web
The Advantages and Disadvantages of JavaScript (Cont.)
|