JavaScript/Introduction
JavaScript is an interpreted programming language that is mostly used to turn static web pages into dynamic and interactive pages after a web browser has finished downloading a web page. For example, a clock displayed on a page that updates itself to show the current time on the user's computer. JavaScript's design was influenced by many programming languages, including C, but is meant to be more usable by non-programmers. JavaScript is not based on or related to Java; this is a common misunderstanding.
JavaScript is often included inside an HTML file or linked to from an HTML file and run locally by a web browser. This means that servers are free to work on something else rather than processing instructions for each client. This has made JavaScript a more popular choice than languages that require a server to do the processing.
Some example uses are:
- rotating or scrolling text.
- making portions of a form visible or invisible. For example in an order form, if the user ticks a checkbox "deliver to different address", an extra section with text boxes with delivery streetname, number, and place may be made visible.
- drop down menus.
- retrieving extra information from the server (Ajax) to partially refresh a page.
- validate user input on a form.
- computations without the need to go back to the server.
- determine browser-type.
- obscure some information from certain types of users, such as email addresses from bots.
Server-side languages such as PHP or Perl are the best way to modify a page before loading, although there are some cases of Server-JavaScript (SJS). Not all browsers have a JavaScript interpreter (such as the text-only browser Lynx), or run its latest version. Furthermore, some users turn off JavaScript capabilities by choice. Generally, web pages should use JavaScript to enhance the user's experience, rather than depend on it. This is often referred to as graceful degradation (i.e if the user has turned off JavaScript, the page should always still load, presenting the same information but without the extra functionality provided by JavaScript.)
[edit] Relation to Java
Despite the similar names, Java and JavaScript, there is almost no relation aside from syntax between the two languages. Since both are frequently used on the Internet, the two can be confused by the uninitiated. In fact they were developed by two totally different companies, with differing goals and purposes in mind: Netscape developed JavaScript and Sun Microsystems developed Java. JavaScript can be interpreted by most browsers directly and quickly, while Java requires a separate "Java Virtual Machine" to be started before running. JavaScript and Java use a similar syntax (based on the C language) but many of the commands are quite different. There are also technical differences. Java is a statically typed language which requires the declaration of all variables and their types (e.g. integer, string or boolean). In contrast, Javascript is a "loosely" typed language, allowing variables to be used without prior declaration.
For example, compare the two methods of writing to the display (page). In Java, to write "Hello world!", the code would read: System.out.println("Hello world!"); while in JavaScript (in a browser), it would say: document.write("Hello world!");.
[edit] About this book
This book is written as a tutorial, in the sense that all key concepts are explained. As such, it also contains exercises that are clearly marked as such at the end of a page or chapter. Answers for these exercises are also included.
The book can also be used as a reference. For this purpose, all keywords are mentioned and described.
[edit] Audience
This book assumes that you have a background in programming. We also assume that you have a good knowledge and some experience in the development of webpages. This book will not explain to you what a webpage is, what HTML tags look like, or what their function is. If you want to learn HTML, please consult the book on HyperText Markup Language.

