Tutorial for understand JavaScript / PDF
Tutorial for understand JavaScript / PDF
Sample of the pdf document
What is JavaScript
Formally, JavaScript is an interpreted, object-oriented programming language. It is often confused with the programming language Java, but they are completely independent languages1. JavaScript has a full set of capabilities that make it just as powerful as many other popular programming languages. To fully cover all the features of JavaScript would require about 1,000 pages of detailed reference text. We will take a more limited approach to the language, covering basic functionality for use in web pages.
For our purposes, we will be using JavaScript as a scripting language that lets us create
dynamic HTML. Instead of static images, JavaScript can be used to make them change based on the users' actions. Instead of programming HTML that will be the same for every user, JavaScript can be used to make the text and appearance different for each person. JavaScript can be used to add interactive features to pages, and add finer control over events. Using JavaScript cookies, data can be stored and passed between pages for personalization or to facilitate more advanced functionality. This is all called Client Side
JavaScript, because the code goes directly in the HTML page.
JavaScript is implemented in Netscape and Mozilla browsers, Safari, the Mac OS X browser, and some other less popular browsers. JavaScript is currently in version 1.5, which is supported in Netscape 6 and later. The previous version of Netscape – version
4.5 – supports JavaScript version 1.3. The language features introduced here are very basic and will generally work in both old and new browsers. When writing JavaScript code, you should consider what browser versions your target audience will be using and use that to make decisions about which features to use.
Microsoft has chosen to implement their own, slightly different version of the language that they call JScript. Though mostly the same as JavaScript, there are some significant differences. Unlike HTML, which works pretty much the same way in every browser, it is more difficult to get JavaScript working in both Internet Explorer and Mozilla/Netscape. In these chapters, the term "JavaScript" will be used as a general term to refer to the core set of code that works in both browser versions.
While we will only look at features that work in both IE and other browsers, it is especially important to
check your JavaScript in all of the major browsers because the chance of errors is much higher.
The good news is that JavaScript is moving toward becoming a standard. The European standards group ECMA as approved ECMA-262, which is a standard language derived from Netscape JavaScript. That standard has also been approved by the International
Standards Organization as ISO-16262. JavaScript has been fully compliant with the ECMA standard since version 1.3. More information about this standardization effort can be found online at the websites for Netscape, ECMA, and ISO.
Getting Started with JavaScript
There is a lot to learn before JavaScript can become an effective and powerful part of your web pages. The next chapter presents all of the syntax basics, but the truth is that learning JavaScript is a process that will produce a lot of errors along the way. Unlike HTML which, at worst, looks a bit strange when there are big coding errors, JavaScript is not forgiving. The smallest error will prevent the code from working at all. Learning to identify these problems, or bugs, in your code will be the most valuable skill you learn.
This section will introduce several features of browsers and the JavaScript language that will be immeasurably useful as you progress.
The JavaScript Console
When an error is found in the code, there must be some way to find it. Thankfully, the browsers are designed to recognize an error in the code and point it out. In Mozilla and Netscape, this is done with the JavaScript Console. The console is a window that lists any JavaScript errors. It can be brought up by going to the Tools menu, selecting Web Development, and then clicking on JavaScript Console (as shown in figure 17.1), or by
typing "javascript:" in the URL bar. If using the latter option, be sure to include the colon after the word "javascript" to bring up the console............
0 commentaires: