Workshop






Workshop

The following workshop includes questions, a quiz, and exercises related to JavaScript.

Q&A

Q

Don't I need a development environment to work with JavaScript?

A

Nope. As with HTML, all you need is a text editor and a browser that supports JavaScript. You might be confusing JavaScript with Java, a more comprehensive programming language that needs at least a compiler for its programs to run.

Q

Are Java and JavaScript compatible?

A

The answer depends on what you mean by compatible. Some of the syntax is similar between Java and JavaScript, but the connection doesn't go much further than that. JavaScript scripts won't compile using a Java compiler, nor can Java programs be included in an HTML file the way JavaScript scripts can. Java programs require a Java compiler and are then included as executable programs in web pages, whereas JavaScript scripts are interpreted in code form as the HTML page is being downloaded.

Q

In Java and C++, I previously defined variables with statements such as int, char, and String. Why can't I do this in JavaScript?

A

As I mentioned previously, JavaScript is a loosely typed language. This means that all variables can take any form and can even be changed on the fly. As a result, the type of value assigned to a variable automatically determines its type.

Quiz

1.

How is JavaScript different from Java?

2.

How is JavaScript similar to Java (other than in name)?

3.

What HTML tag did Netscape introduce to identify JavaScript scripts?

4.

What are events? What can JavaScript do with them?

5.

How are functions different from methods?

Quiz Answers

1.

JavaScript is a simple language that works only in web browsers; Java is a more comprehensive programming language that can be used just about anywhere.

2.

Because JavaScript scripts are run by the web browser itself, they're portable across any browser that includes JavaScript support, regardless of the computer type or operating system (like Java).

3.

To accommodate the inclusion of JavaScript programs in a normal HTML document, Netscape introduced the <script> tag. By placing a <script> tag in a document, you tell the web browser to treat any lines of text following the tag as script rather than as content for the web page.

4.

Events are special actions triggered by things happening in the system (windows opening, pages being loaded, forms being submitted) or by reader input (text being entered, links being followed, check boxes being selected). Using JavaScript, you can perform different operations in response to these events.

5.

Methods are associated with a specific object, and functions are standalone routines that operate outside the bounds of an object.

Exercises

1.

If you haven't done so already, take a few minutes to explore Netscape's online documentation for JavaScript at http://devedge.netscape.com/central/javascript/. See whether you can find out what enhancements were included in JavaScript 1.5 that weren't included in earlier versions.

2.

Find a simple JavaScript script somewhere on the Webeither in use in a web page or in an archive of scripts. Look at the source code and see whether you can decode its logic and how it works.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows