Script | answer | questions
If not meticulous, any programming language has some possible errors, and each language has its own special place. For example, for null values: This value in JScript does not function as a null value in C or C + + languages.
The following are some of the issues you might encounter when writing a JScript script.
Syntax error
Because the syntax of a programming language is much stricter than that of a natural language, the details should be paid more attention to when writing scripts. For example, if you intend to use a string as a parameter, but you forget to enclose it in quotation marks as you type, a problem arises.
Script Interpretation Order
The interpretation of JScript is part of the HTML parsing process of the Web browser. Therefore, if a script is placed in the <HEAD> ID of the document, it will be interpreted before all the <BODY> identities are checked. If objects are created in the <BODY> identity, they cannot be scripted because they do not already exist because of the parse process <HEAD> identity.
Note that this situation is specific to IE. ASP and WSH have different operating modes (other hosts are also).
Automatic type coercion
JScript is a free type language with automatic coercion. Therefore, although different types of values are actually unequal, the expression evaluated in the following example will get true.
"100" == 100;false == 0;
To reconcile types with values, use the "strict equality" operator (= = =). The value of the following two expressions is false:
"100" === 100;false === 0;
Operator Precedence
When evaluated on an expression, the execution of a particular operator is primarily based on the operator precedence , not the position of the expression. Therefore, in the following example, multiplication is performed before subtraction, although the first operator to appear in the expression is subtraction.
theRadius = aPerimeterPoint - theCenterpoint * theCorrectionFactor;
Using for...in loops for objects
When you use the for...in loop to traverse the properties of an object, you do not have to predetermine or manage the order of the object fields that will be assigned to the loop counter variable. In addition, the order may vary in different implementations of the language.
with keyword
The WITH statement can be conveniently used to refer to an existing property in a particular object, but cannot be used to add attributes to an object. To create a new property for an object, you must explicitly refer to the object.
this keyword
Although you can refer to the object itself by using the This keyword within the scope of the object's definition, you cannot use this or a similar keyword to refer to the current execution function as usual when the function is not the object's definition. If the function is specified as a method of an object, you can use the This keyword within that function to refer to the object.
Write a script that writes the script in IE
The current script is terminated when an interpreter encounters a </SCRIPT> tag. To display the </SCRIPT> itself, rewrite it to at least two strings, such as "</SCR" and "ipt>", so that you can connect them together in an output statement.
Implicit window references in IE
Because you can open multiple windows at the same time, any implicit window references are pointed to the current window. You must use an explicit reference for other windows.