159Chapter 13JavaScript Essentials .JavaScript is loosely (Fedora web server) typed.Variables, arrays,

159Chapter 13JavaScript Essentials .JavaScript is loosely typed.Variables, arrays, and function return values are notdefined to be of any particular data type. In fact, an initialized variable can hold differ- ent data type values in subsequent script statements (obviously not good practice, butpossible nonetheless). Similarly, an array may contain values of multiple types. Therange of built-in data types is intentionally limited: Boolean (trueor false) Null Number (double-precision 64-bit format IEEE 734 value) Object (encompassing the Arrayobject) String Undefined .The host environment defines global scope.Web browsers traditionally define abrowser window or frame to be the global context for script statements. When a doc- ument unloads, all global variables defined by that document are destroyed. .JavaScript variables have either global or local scope. A global variable in a Webbrowser is typically initialized in varstatements that execute as the document loads. All statements in that document can read or write that global variable. A local variableis initialized inside a function (also with the varoperator). Only statements inside thatfunction may access that local variable. .Scripts sometimes access JavaScript static object properties and methods.Somestatic objects encourage direct access to their properties or methods. For example, allproperties of the Mathobject act as constant values (for example, Math.PI). .You can add properties or methods to working objects at will.To add a property toan object, simply assign a value of any type to it. For example, to add an authorprop- erty to a string object named myText, use: myText.author = Jane ; Assign a function reference to an object property to give that object a new method: // function definitionfunction doSpecial(arg1) { // statements} // assign function reference to method namemyObj.handleSpecial = doSpecial; … // invoke methodmyObj.handleSpecial(argValue); Inside the function definition, the thiskeyword refers to the object that owns themethod. .JavaScript objects employ prototype-based inheritance.All object constructors cre- ate working objects whose properties and methods inherit the properties and methodsdefined for the prototypeof that object. Starting with NN3 and late versions of IE3, scripts can add and delete custom properties and/or methods associated with thestatic object s prototype so that new working objects inherit the current state of the