understanding javascript

JavaScript is a programming language that's built into your web browser and lets you manipulate the images, text, and other objects that appear in the browser window.

JavaScript is responsible for many of the dynamic elements in today's web's sites. Some, like image rollovers, are visible to the user. And others work behind the scenes to detect, for example, what type of browser the visitor is using and customize the page accordingly.

The real power of JavaScript is that it's a client-side programming language, which means it can perform all sorts of functions within a web page and without help from the server. Once a page with JavaScript appears in a browser, it has everything it needs to perform lightweight programming functions, such as calculating totals, swapping images, or expanding and collapsing menus. So these tasks can be completed without a new page loading.

The benefits of JavaScript:

  • It's built into the browser, so it can manipulate the words and images in the window more easily than other programming languages.

  • It can interact with the user's computer, gleaning basic information about the user's environment (platform, browser, etc.).

  • It's relatively easy to learn more difficult than HTML, but much easier than complex programming languages like Java or C++.

  • JavaScript programs are generally short and sweet, and they can be integrated right into the HTML document.

  • JavaScript code can be shared easily among developers. You can cut and paste a script from one HTML page to another.

  • JavaScript programs are self-sufficient. They run in a user's browser, without relying on the site server for help.

what you need to know about javascript

what it is

JavaScript is a programming language built directly into the web browser. It's a relatively simple language that's easy to learn and integrate.

how it's used

JavaScript is used to add interactive elements including image rollovers and image maps to a web page. It's also used for launching small pop-up windows, running a "ticker" along the browser frame, gathering information from forms, expanding and collapsing menus, and detecting the user's browser and platform.

why it's loved

JavaScript was the first and still one of the most accessible ways to bring interactivity to otherwise static web pages.

  • It's relatively easy to learn.

  • It's easy to steal and customize scripts.

  • It adds interactive elements with relatively little programming work.

  • It doesn't put a strain on the server.

  • It allows easy access to the elements on the web page.

why it's hated

People love to hate JavaScript because:

  • Different browsers support JavaScript differently. So a program that works in one browser might crash another.

  • Inexperienced programmers create buggy scripts that don't work consistently.

  • Some common applications like ticker tape or pop-up windows are overused and annoying, but they just don't go away.


Like most technologies, JavaScript is a double-edged sword. Its powers can be used for good or evil. Most of the problems with JavaScript stem from its overuse or misuse.

The drawbacks of JavaScript:

  • Different browsers support JavaScript differently. A program that works effortlessly in one browser may choke in another.

  • The accessibility of JavaScript means there are many novice programmers producing buggy, inconsistent code.

  • Because JavaScript can be shared so easily among sites, many non-programmers integrate JavaScript into their sites without understanding what they're doing or why.

learning to use javascript

JavaScript programs are integrated directly into the HTML document (in the header area at the beginning of the document) and are sandwiched between the <script> </script> tags.

The code for a Javascript alert box will look like this:

 
 <script language="JavaScript"> alert("Here's something you can do with JavaScript"); </script> 
 

And will appear on screen like this:

graphics/165fig01.gif

This example is very simple. And that again is the beauty of JavaScript: You can easily learn to do some simple tricks just by copying another site's code. But if you really want to learn JavaScript, it's best to take a more structured approach.

other programming options

VBScript Developed by Microsoft, VBScript is similar to JavaScript and serves the same purpose: to let programmers easily manipulate the object in a browser window. But VBScript only works on Microsoft's Internet Explorer browser, running in Microsoft Windows. This makes it a poor choice for most sites.

Server-side scripts These can accomplish many of the same things as JavaScript, but they rely on the site's server to get things done. They're primarily used to pass information between the user and a database or application. See understanding php, p. 168.

Java Although they sound related, Java and JavaScript have little in common. Java is a full-featured, object-oriented programming language, similar to (though simpler than) C++. It was developed by Sun Microsystems as an agnostic language that works across all platforms. It's used (among other things) to develop small web-based applications ("applets") that download with a web page.


Learning JavaScript is a dual process:

  • Learning to think with the structural logic of an engineer

  • Learning JavaScript itself

Learning a programming language is a lot like learning a real language. You have to learn both the words (called "variables") and the grammar (or "syntax") used to string the words together. The best place to start is Webmonkey's JavaScript tutorial, written by web veteran Dave Thau. His book The Book of JavaScript, is a great follow-up.

Learn JavaScript

Webmonkey JavaScript tutorials

http://www.webmonkey.com/programming/javascript/

A List Apart JavaScript tutorials

http://www.alistapart.com/stories/indexJavaScript.html


Buy this book!

graphics/buy.gif

The Book of JavaScript

By thau!

(No Starch, $29.95)




The Unusually Useful Web Book
The Unusually Useful Web Book
ISBN: 0735712069
EAN: 2147483647
Year: 2006
Pages: 195
Authors: June Cohen

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