JavaScript (JS) is the dominant client-side scripting language of the Web. JS is a dynamic (or interpreted: Executes somethings at run-time instead of at compiling), weakly-typed (or loosely-typed: A variable may change its data type), prototype-based (object oriented but instead of classes, the .prototype of an instance affects all other instances) programming language with first-class functions (functions can be first-class objects which allows their creation and modification at run-time) and closures (functions can enclosed as a parameter of another function AND can refer to bound variables, i.e. variables visible at the time the enclosing function was defined).

History

JavaScript was developed by Brendan Eich at Netscape Communications Corporation, first as Mocha, then as LiveScript, then as JavaScript as part of the Netscape browser v2.0B3 in 1995-12. JavaScript has no relation to Java other than they both use a syntax similar to the c language and that Java was the hot new language at the time. EG: c is a procedural language, while c++ is class-based object oriented language, while JavaScript is a prototype-based object oriented language (like the language Self). JavaScript became widely popular and Microsoft implemented it as JScript in Internet Explorer 3.0 in 1996-08. Netscaped submitted JavaScript to Ecma International for standardization, which resulted in ECMA-262 or ECMAScript in 1997-06. Since then ECMAScript is the standard and it has various dialects, some with their own extensions, and some (EG: Flash's ActionScript) that are quite different. The main dialects includes Netscape's/Mozilla's JavaScript and Microsoft's JScript.

DateJavaScriptJScriptECMAScriptActionScript
1996-031 in NS 2
1996-081.1 in NS 31 in IE 3
1997-012 in IIS 3
1997-061.2 in NS 41
1997-103 in IE 4 and VS 6
1998-062
1998-101.3 in NS 4.06
1998-101.4 in NS 4.7
1999-035 in IE 5
1999-123
200031 in Flash Player 5
2000-075.5 in IE 5.5
2000-111.5 in NS 6 and FF 1
2001-105.6 in IE 6
200332 in Flash Player 7
2005-111.6 in FF 1.5
2006-0633 in Flash Player 9
2006-101.7 in FF 2
2006-115.7 in IE 7
2008-101.8 in FF 3
2009-035.8 in IE 8
1.8.1 in FF 3.5
2009-061.8.2 in FF 3.6
2009-125. (4 was abandoned.)
2010-071.8.5 in FF 4in IE 9

JavaScript Engines

JavaScript source code is interpreted and executed by a JavaScript engine.

  • JavaScript is famous for its "client-side" use, hence most JavaScript engines are in web browsers. A web browser also has a layout engine (aka web browser engine; rendering engine) which handles markup (HTML, XML, etc.) and formatting info (CSS, XSL, etc.) and generates the out put for display. Browsers, JavaScript engines, and layout engines are related but distinct.
  • JavaScript may also be used on the "server-side", hence there are JavaScript engines for web servers, or web servers that are JavaScript engines.

While each JavaScript engine generally try to conform with the ECMAScript standard, they stray. Hence each JavaScript engine has its own dialect of JavaScript/ECMAScript.

Client-side JavaScript Engines:

  • Netscape/Mozilla/Firefox browsers:
    • SpiderMonkey JavaScript engine. Written in c. Used server-side and client-side. The original JavaScript written by Brendan Eich for Netscape, but now managed by Mozilla where Eich is CTO (2008).
    • Gecko layout engine. Developed by Mozilla but started by Netscape in 1997. Used by browsers and software like these:
      • Firefox
      • Camino
      • Flock
      • Netscape Navigator 9
      • Galeon
      • Epiphany
      • K-Meleon
      • The Mozilla Thunderbird email and news client.
      • The Mozilla SeaMonke internet suite.
      • Songbird
      • Lunascape
      • Kazehakase
  • Internet Explorer browser by Microsoft
    • Trident (aka MSHTML) layout engine. Developed by Microsoft. Used by the Internet Explorer (cross platform) browser versions 4-8.
    • Chakra JavaScript engine. Developed by Microsoft for Internet Explorer 9.
    • JScript. The Microsoft dialect of ECMAScript. Includes three variations of JScript: "Classic JScript" (which is very much like JavaScript), Managed JScript, and JScript .NET.
  • WebKit application framework. An open source fork from the KHTML layout engine. Written in c++.
    • WebKit [webkit.org]. Official site.
    • Used by browsers and software like these:
      • Apple Safari
      • Google Chrome
      • OmniWeb
      • Shiira
      • iCab
      • The Adobe Integrated Runtime (Adobe AIR) runtime environment.
    • WebCore rendering engine
    • JavaScriptCore JavaScript engine. Later versions called SquirrelFish. Derived from KDE's JavaScript (KJS) engine.
    • V8 JavaScript engine. Used in the Chrome browser. Written in c++. Open source.
    • Drosera JavaScript debugger. Comes with WebKit.
  • Opera browser
    • Presto layout engine.
    • Various ECMAScript engine for Opera:
      • Linear A. Used in Opera 4.
      • Linear B. Used in Opera 7-9.
      • Futhark. Used in Opera 9.5-10.
      • Carakan. Used in Opera 10.5-11.
  • Konqueror browser for Unix-like systems
    • KDE's JavaScript (KJS) engine.
    • KHTML layout engine. Written in c++.
  • Adobe Flash apps. Not a browser but used in browsers.

Server-side JavaScript Engines:

While the Client-Side JavaScript (CSJS) is well known, the Server-Side JavaScript (SSJS) is not. Personally, I like JavaScript and why not use it on the server-side? See also "CommonJS effort sets JavaScript on path for world domination" [http://arstechnica.com/web/news/2009/12/commonjs-effort-sets-javascript-on-path-for-world-domination.ars], ca 2009-12-01.

  • JScript. "Classic ASP" is more known for VBScript, but JScript (Microsoft's variant of JavaScript) and PerlScript could also be used for Classic ASP.
  • Aptana Jaxer is based on SpiderMonkey JavaScript.
  • LiveWire by Netscape is probably the oldest SSJS.
  • CommonJS [http://wiki.commonjs.org/wiki/CommonJS] by Kevin Dangoor is used by other SSJS implementations. Formerly known as ServerJS.
  • Rhino JavaScript engine. Developed by Sun but managed by Mozilla. Open source and written in Java. Used especially on the server-side.
  • AppJet by Ryan Dahl focused on their EtherPad product for browser collaboration apps, but was bought ought by Google and supplanted by Google Docs.
  • NodeJS also by Ryan Dahl. Built on V8 for Unix-like platforms. Implements some CommonJS specs.
  • Narwhal by Tom Robinson. Built on V8.
  • Wakanda based on SquirrelFish JavaScript.

Libraries

Except for the simplest of sites, it seems that the days are slipping when you could make a site with your own HTML, CSS, AJAX, and JavaScript on the client-side, plus whatever on the server-side. See http://www.surveymonkey.com/sr.aspx?sm=fXLiKcnKlD6cO5bRe961aBB6NCCWytRyY3rParAYmwA_3d. Now it seems that you have to use a library, as in the old build v buy argument. It's not simply for pretty stuff but for serious business stuff like data grids. They're calling them {AJAX | Widget | Web App} {Toolkits | Frameworks} these days. You can simply call them JavaScript libraries on the client-side, but on the server-side it's usually some other language generating JavaScript, CSS, and HTML for the client-side.

Some of the top client-side JavaScript libraries :

  • Dojo Toolkit
  • Ext JS. My favorite!
  • Google Closure
  • jQuery
  • Midori
  • MochiKit
  • Prototype JavaScript Framework
  • qooxdoo
  • Rialto
  • Script.aculo.us
  • Spry
  • Yahoo! User Interface (YUI)

The top server-side "JavaScript" libraries include:

There are libraries with more specific uses that are often included. Here are a few arbitrary ones:

  • Datejs. For dates.
  • Some Lightbox [W] variation for pretty pictures.

Miscellany

Here are some miscellaneous items regarding JavaScript.

  • Special characters can be inserted into literal strings, including the following that correspond with the escaped characters in Regular Expressions: \b\t\n\v\r\e\"\'\cx\on\xn\un.
  • JS uses the try ... catch ... finally and throw statements for error handling.VBS uses On Error and Next for error handling.
  • JS is case sensitive. VBS is not.
  • JS allows implicit or explicit variable declarations.
    • JS has no way of requiring explicit decarations like the Option Explicit feature of VBS.
    • There are general two scopes in JS: function scope and application/global scope.
    • If a variable is used that has not been explicitly declared with var, then JS assumes implicit variable declaration and that the variable is of the application/global scope.
    • The delete operator can be used on an implicitly declared variable but not an explicitly declared one or those part of the JS language.
  • JS is available for client-side scripting on most browsers, whereas VBS is usually available only for Microsoft Internet Explorer.
  • JS probably has a larger body of resources and code out there than VBS because JS has been around longer.
  • There are two types of JavaScript comments:
    //This is a single line comment.
    
    /* This is the start of a multi-line comment.
    This is the end of a multi-line comment. */
    
  • An HTML <a> tag can call a JS function directly with this syntax: <a href="javascript:functionName()">.
  • Script within a <script> tag is often enclosed in an SGML comment declaration so that non-script using browsers can ignore the script. The close of the SGML comment is often commented out with a JS comment. EG:
    <script type="text/JavaScript">
    <!-- // Hide script from no-script browsers.
        Multiple lines of script may go here.
    // End with a JS comment. -->
    </script>
  • JS is weakly-typed (loosely-typed): A variable may change its data type. This is powerful but can be a common source of errors so a clear understanding of this is needed and developers must be keenly aware of any automatic type-conversions (type-castings).
    • Here are only 6 types in JS: boolean, function, number, object (includes null, arrays, and regexps), string, and undefined. In an ideal world null, array, and regexp would be their own types in order to match the JS Standard objects.
    • For evaluating expressions as a boolean in JS: If expression is omitted or evaluates to 0, -0, null (not 'null'), false (not 'false'), NaN (not 'NaN'), undefined (not 'undefined'), or an empty string ("" or ''), then the object has an initial value of false. All other values will evaluate to true. EG:
      null==undefined;   // auto type-conversion, so true
      null===undefined;  // strict or no type-conversion, so false
    • For evaluating expressions as numbers in JS: Literal integers (EGs: 13, 07 (octal), 0xF7 (hexadecimal)) and floating-point literals (EGs: 3, 3.1, -3.2e-7) have the value stated, but others depend on context. undefined variables get treated as NaN. null variables get treated as 0. Empty string can be 0 (EG: Number("")) or can auto type-convert its neighbors (EG: 8+""+8 yields 88 not 16).
    • A mixture of types can only occur for binary operators. If a given binary operator only supports one type, then both pieces of data for that operator must either be of that type, or convertible to that type, otherwise an error results.
      • For + operators, if either argument is a String or converts preferentially to one, then it does string concatenation, not numeric addition. Otherwise, if neither argument prefers to be a string, then it does numeric addition. (Short version: "+ is either string")
      • For >, >=, <, <= operators, if neither argument can be converted to a number, then it does string comparison, not numeric comparison. Otherwise, if at least one argument can be converted to a number, then it does numeric comparison. (Short version: "compare is neither number")
      • For ==, != operators, first convert any Objects to their preferred primitive types. If the types are still different, convert any Boolean to a Number. If the types are still different, convert the non-Number argument to Number and compare as Numbers. Exception: null==undefined without any conversion defined.
    • Force the conversion if mixed types must be compared. EG:
      x = ( a+'' == b+'')  //String comparison forced 
      x = ( a -0 == b -0)  //Number comparison forced 
      x = ( !a   == !b  )  //Boolean comparison forced
      
    • Avoid comparing things with null, instead trust that the conversion to the Boolean type will work. EG:
      if ( a != null) { ...}   //may be buggy
      if ( a        ) { ...}   //better
      
    • On the other hand, the variable you get may have been explicitly converted into a string at some point, in which case then you can check for literal "null", "undefined", "true", "false", etc.
  • JS can only handle event procedures by explicitly linking an object with a function. EG: <img .... onmouseover="RunMe()">. VBS on the other hand can also handle event procedures by making procedures whose name follows this syntax: Object_Event(). Multiple JS statements can be included in the explicit event link.


GeorgeHernandez.comSome rights reserved