Introducing JavaScript and JScript

[ LiB ]

Introducing JavaScript and JScript

JavaScript is a computer language specially designed to work with Internet browsers. It lets you create small programs called scripts and embed them inside Hypertext Markup Language (HTML) pages in order to provide interactive content on your Web pages. JScript is Microsoft's implementation of JavaScript. In addition to running within Internet Explorer, Microsoft also provides a version of JScript that can be used as a desktop scripting language with the Windows Script Host.

The WSH is an optional scripting environment that supplies Windows operating systems with the capability to run scripts directly on the Windows desktop. Both languages support the same collection of programming statements.

JavaScript and JScript are interpreted languages. This means that scripts written in these languages are not compiled before they are executed (as is typical of most programming languages such as C++). Every script statement must first be converted into binary code (a computer language made up of 0s and 1s that the computer can understand) in order to execute. Unlike complied programs, which are converted to binary code in advance, JavaScript and JScript statements are processed at execution time. This means that they run a little slower than compiled programs. The upside is that this makes writing and testing JavaScripts and JScripts very intuitive and easy. You simply write a few lines of code, save your script, and test it without having to stop and compile it into executable code.

JavaScript and JScript are object-based scripting languages. This means that they view everything as objects . For JavaScripts, the browser is an object, a window is an object, and a button in a window is an object. JScript has access to a different set of objects. For example, JScript has the capability to access objects such as files, drives , and printers.

Every object has properties , and you can use JavaScript and JScript to manipulate these properties. For example, with JavaScript you can change the background color of a browser window or the size of a graphic image. In addition to properties, objects have methods . Methods are the actions that objects can perform. For example, JavaScript can be used to open and close browser windows. By manipulating their properties and executing methods, you can control objects and make things happen.

JavaScripts support event-driven programming . An event is an action that occurs when the user does something such as click on a button or move the pointer over a graphic image. JavaScript enables you to write scripts that are triggered by events. Did you ever wonder how buttons dynamically change colors on some Web sites when you move the mouse over them? It's simply a JavaScript technique known as a rollover . The event is the mouse moving over the button (object). This triggers the execution of an event handler , which is a collection of JavaScript statements that replaces the button with another one that uses a different color.

JavaScripts and JScripts that run within Web browsers have access to objects located on Web pages. On the other hand, JScripts that run within the WSH have access to desktop resources such as toolbars , files, printers, and the Windows registry.

Because JavaScript and JScript run in different environments, they work with different objects, and they have different capabilities. For example, using JScript you can create scripts that can copy and move files, access data stored on network drives, administer local and network printers, and configure the Windows desktop and Start menu.

Because JavaScript and JScript are so closely related , you can learn one language by learning the other. The difference between the two resides in the location in which they execute and the objects to which they have access. Tomorrow morning you will get a thorough language review of all the statements that make up JavaScript and JScript. Because the first part of this book focuses on JavaScript, all the examples will be presented using that language. However, from a programming standpoint, most of the scripting statements that you will see can be applied directly to JScript programming.

[ LiB ]


Learn JavaScript In a Weekend
Learn JavaScript In a Weekend, Second Edition
ISBN: 159200086X
EAN: 2147483647
Year: 2003
Pages: 84

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net