



























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




























































➢ Originally developed by Netscape ➢ Joint Development with Sun Microsystems in 1995 ➢ Standard 262 (ECMA-262) of the European Computer Manufacturers Association ➢ ECMA- 262 edition 3 is the current standard
XHTML/JavaScript Documents ➢ When JavaScript is embedded in an XHTML document , the browser interpret ‘s it with Java Interpretor to run or execute. ➢ Two locations for JavaScript server different purposes
JavaScript in XHTML: CDATA ➢ The **** block is intended to hold data that should not be interpreted as XHTML ➢ Using this should allow any data (including special symbols and -- ) to be included in the script ➢ This, however does not work, at least in Firefox: __ ➢ The problem seems to be that the CDATA tag causes an internal JavaScript error JavaScript in XHTML ➢ This does work in Firefox __ ➢ The comment symbols do not bother the XML parser (only /* and */ are ‘visible’ to it) ➢ The comment symbols protect the CDATA markers from the JavaScript parser
➢ Directly embedded < **_script type=“text/javascript”>
** ➢ However, note that a-- will not be allowed here! ➢ Indirect reference ** General Syntactic Characteristics ➢ Identifiers
Primitive Types ➢ Five primitive types
Primitive and Object Storage
Declaring Variables ➢ JavaScript is dynamically typed , that is, variables do not have declared types
Precedence of Operators Operators Associativity ++, --, unary - (^) Right *, /, % (^) Left +, - (^) Left >, <, >= ,<= (^) Left ==, != (^) Left ===,!== (^) Left && (^) Left || (^) Left *=, +=, - =, =, /=, &&=, ||=, %= (^) Right Example of Precedence: var^ a = 2,b = 4,c,d; c = 3 + a * b; // * is first, so c is now 11 (not 24) d = b / a / 2; // / associates left, so d is now 1 (not 4) Special: = = = : 1 = = “1” returns true, but its not, so 1 === “1” returns false
String Catenation ➢ The operation + is the string catenation operation ➢ In many cases, other types are automatically converted to string Implicit Type Conversion ➢ JavaScript attempts to convert values in order to be able to perform operations ➢ “August “ + 1977 causes the number to be converted to string and a concatenation to be performed ➢ 7 * “3” causes the string to be converted to a number and a multiplication to be performed ➢ null is converted to 0 in a numeric context, undefined to NaN ➢ 0 is interpreted as a Boolean false , all other numbers are interpreted a true ➢ The empty string is interpreted as a Boolean false, all other strings (including “0”!) as Boolean true ➢ undefined, Nan and null are all interpreted as Boolean false
Explicit Type Conversion ➢ Explicit conversion of string to number
Example: Var str=“George” var len = str.length; // Str.charAt(2) //o str.indexof ( ‘ r ’ ) // Str.substring(2,4) //or Str.toLowerCase() /george
The typeof Operator ➢ Returns type of single operand ➢ Returns “number” or “string” or “boolean” for primitive types ➢ Returns “object” for an object or null ➢ Two syntactic forms