|
|
JavaScript |
JavaScript Classes |
JavaScript FAQ
JavaScript FAQ
Table of Contents: JavaScript FAQ
- What is JavaScript?
- Where can I find online documentation for JavaScript?
- What are the language's basic entities?
- How is JavaScript syntax like C / C++?
1. What is JavaScript?
JavaScript is a platform-independent, event-driven, interpreted programming language developed by Netscape Communications Corp. and Sun Microsystems. Originally called LiveScript (and still called LiveWire by Netscape in its compiled, server-side incarnation), JavaScript is affiliated with Sun's object-oriented programming language Java primarily as a marketing convenience. They interoperate well but are technically, functionally and behaviorally very different.
JavaScript is useful for adding interactivity to the World Wide Web because scripts can be embedded in HTML files (i.e., web pages) simply by enclosing code in a <SCRIPT> </SCRIPT> tag pair. All modern browsers can interpret JavaScript -- albeit with some irritating caveats. (More about them below.)
In practice, JavaScript is a fairly universal extension to HTML that can enhance the user experience through event handling and client-side execution, while extending a web developer's control over the client's browser. And that's worth a FAQ.
2. Where can I find online documentation for JavaScript?
3. What are Javascript's basic entities?
A. As in most object-oriented, event-driven
programming languages, there are four distinct entities in JavaScript:
- OBJECTS. A discussion of objects is beyond the scope of this FAQ. It's impossible to understand JavaScript
without knowing the following essentials, however:
- everything you can control in a web browser is an object comprising properties and methods (sometimes referred to in the literature as attributes and operations, respectively)
- properties define the state of an object; e.g., red text, 10-element array
- methods define the actions that change the state of an object; e.g.,
fontcolor("red") sets the color of a text object to red.
- FUNCTIONS. Methods that operate outside of objects; e.g.,
escape() and unescape(), JavaScript functions that perform ASCII to hex conversions. The existence of non-object-specific functions in JavaScript keeps it from being a truly object-oriented language like Java.
- STATEMENTS. Programming commands that control object lifecycles and the flow of execution; e.g.,
if..else, while. JavaScript statements and syntax closely resemble those of the 'C' programming language.
- EVENTS. Things that happen, usually as a result of user actions, to which a JavaScript program can
respond; e.g., a mouse click. Events always happen in relation to a given object, such as a button in a form (for which
onClick is a typical event), or an entire web page (sample event: onLoad). The code that specifies what the object should do in response to an event is a special type of method called an event handler.
4. How is JavaScript syntax like C / C++?
The languages have enough in common to make learning one easy if you know the other. By the same token, the differences are subtle enough to trip up those proficient in both. Here's a short list comparing C and JavaScript:
- Terminating JavaScript command lines in semicolons is optional; in C it's mandatory. Recommended practice is to use them religiously in both languages (and Java as well).
- Both JavaScript and C are case-sensitive; 'doThis' is different from 'DOTHIS'. Experienced programmers learn to love this feature, which drives beginners nuts.
- Both JavaScript and C are block-structured computer languages and employ curly brackets -- '{' and '}' -- to delimit blocks.
- Both JavaScript and C employ quotation -- enclosure in single or double quote marks -- to designate text strings.
- Arrays in both JavaScript and C are zero-based; the first element is myArray[0], not myArray[1].
- Both JavaScript and C employ '==' for comparison, '=' for equality, and '!' for negation. In fact the set of JavaScript operators is essentially borrowed from C (right down to the deprecated ternary construct a ? b : c).
- Both JavaScript and C employ the symbols /* to designate a comment */. JavaScript also permits the use of '//' for short comments, as in C++.
- Finally, JavaScript's statements are a strict subset of C++'s, offering a smaller selection of identical looping and conditional constructs.
Home |
Technical Schedule |
Application Classes |
Class Outlines |
MCSE, MCDBA, MCSD Training |
Microsoft .NET Programming |
Cisco Classes |
Linux, Unix, AIX |
CompTIA Certification |
Webmaster Training |
Pricing |
Locations |
Financing |
E-mail Us
|