TAGS: JavaScript, Programming, TECH
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 without classes but instead uses and possibly modifies instances or prototypes) programming language with first-class functions (functions can be first-class objects which allows their creation and modification at run-time).
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 not 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. 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 and JScript .NET.
Here are some miscellaneous items regarding JavaScript.
try ... catch ... finally and throw statements for error handling.VBS uses On Error and Next for error handling.Option Explicit feature of VBS.var) then JS assumes implicit variable declaration and that the variable is the largest scope applicable.//This is a single line comment.
/* This is the start of a multi-line comment.
This is the end of a multi-line comment. */
<a> tag can call a JS function directly with this syntax: <a href="javascript:functionName()">.<script type="text/JavaScript">
<!-- //Hide script from no-script browsers.
Multiple lines of script may go here.
//End with a JS comment. -->
</script>
Infinity. A numeric value representing infinity. Initially equivalent to Number.POSITIVE_INFINITY.NaN. A value representing Not-A-Number. In pseudo-code: NaN <> NaN <> Number.NaN, so use isNaN() for comparison instead.undefined. A variable that has not been assigned a value is of type undefined.null==undefined; //auto type-conversion, so true null===undefined; //strict or no type-conversion, so false
+ 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")>, >=, <, <= 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")==, != 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.x = ( a+'' == b+'') //String comparison forced x = ( a -0 == b -0) //Number comparison forced x = ( !a == !b ) //Boolean comparison forced
if ( a != null) { ...} //may be buggy
if ( a ) { ...} //better
<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.2008-03-17 22:30:42Z