JavaScript: Object-Based Scripting for the Web
JavaScript is an object-based scripting language with strong support for proper software engineering techniques. Students learn to create and manipulate objects from the start in JavaScript. JavaScript is available free in today’s popular web browsers.
Does JavaScript provide the solid foundation of programming principles typically taught in first programming courses—a portion of the intended audience for this book? We think so.
The JavaScript chapters of the book are more than just an introduction to the lan- guage. They also present an introduction to computer programming fundamentals, including control structures, functions, arrays, recursion, strings and objects. Experienced programmers will read Chapters 6–13 quickly and master JavaScript by reading our live- code examples and by examining the corresponding screenshots. Beginners will learn com- puter programming in these carefully paced chapters by reading the code explanations and completing the many exercises.
JavaScript is a powerful scripting language. Experienced programmers sometimes take pride in creating strange, contorted, convoluted JavaScript code. This kind of coding makes programs more difficult to read, test and debug. This book is also geared for novice programmers; for all readers we stress program clarity.
Good Programming Practice 1.1
Write your programs in a simple and straightforward manner. This is sometimes referred to as KIS (“keep it simple”). One key aspect of keeping it simple is another interpretation of KIS— “keep it small.” Do not “stretch” the language by trying bizarre uses. 1.1
You’ll see that JavaScript is a portable scripting language and that programs written in JavaScript can run in many web browsers. Actually, portability is an elusive goal. \
Portability Tip 1.2
Although it is easier to write portable programs in JavaScript than in many other programming languages, differences among interpreters and browsers make portability difficult to achieve. Simply writing programs in JavaScript does not guarantee portability. Programmers occasionally need to research platform variations and write their code accordingly. 1.2
Portability Tip 1.3
When writing JavaScript programs, you need to deal directly with cross-browser portability is- sues. Such issues are hidden by JavaScript libraries (e.g., Dojo, Prototype, Script.aculo.us and ASP.NET Ajax) which provide powerful, ready-to-use capabilities that simplify JavaScript cod- ing by making it cross-browser compatible. 1.3
Error-Prevention Tip 1.1
Always test your JavaScript programs on all systems and in all web browsers for which they are intended. 1.1
Good Programming Practice 1.2
Read the documentation for the JavaScript version you are using to access JavaScript’s rich col- lection of features. 1.2
Error-Prevention Tip 1.2
Your computer and JavaScript interpreter are good teachers. If you are not sure how a feature works, even after studying the documentation, experiment and see what happens. Study each er- ror or warning message and adjust the code accordingly. 1.2
JavaScript was created by Netscape, the company that created the first widely suc- cessful web browser. Both Netscape and Microsoft have been instrumental in the stan- dardization of JavaScript by ECMA International (formerly the European Computer Manufacturers Association) as ECMAScript. In Chapters 16–17, we discuss Adobe Flash, which uses another scripting language named ActionScript. ActionScript and JavaScript are converging in the next version of the JavaScript standard (JavaScript 2/ECMA Script version 4) currently under development by ECMA. This will result in a universal client scripting language, greatly simplifying web application development.