One, with statements
Using the WITH statement simplifies some types of javascript statements by reducing multiple references to one object to a reference, and references to properties and methods in the With block are treated as references to objects.
<Script>string= "The quick brown for jumps over the lazy dog" with(String) {document.write ("The string is" +length+ "characters<br/>") document.write ("In upper case it ' s" +touppercase ())}</Script>
In the above code, the JavaScript compiler recognizes that the length property and the toUpperCase method must be applied to an object, and the compiler considers them to be related to the string object specified in the WITH statement.
Ii. use of the OnError event
Events are behaviors that can be detected by JavaScript, and each element on a webpage has certain events that can be used to start JavaScript functions. The OnError event can redefine the action that is performed when an error is detected.
<Script>onerror=Errorhandlerdocument.writ ("Welcome to this website")functionErrorHandler (message,url,line) {out= "Sorry,an error was encountered.\n\n"; out+= "Error:" +message+ "\ n"; out+= "URL:" +URL+ "\ n"; out+= "Line :" + Line+ "\ n"; out+= "Click OK to continue.\n\n"; alert (out); return true;}</Script>
Iv. catching exceptions using the Try ... catch statement
The Try...catch statement is more standard than the onerror technique, which catches exceptions in the selected block of code, rather than the entire script. Of course, they do not catch syntax errors and need to be onerror to catch syntax errors.
<Scripttype= "Text/javascript"> Try { //Do somethings } Catch { //If you catch an error } finally { //The code in this block of statements is executed regardless of the error. }</Script>
V. CONDITIONS and CIRCULAR statements
The conditions and loops of javsscript are basically consistent with C + +: If ... else, switch ... while and for loops, and break and continue that jump out of the loop are not produced much.
JavaScript control flow and expressions