Posted 21 years ago on 3/19/2003 and updated 3/1/2008
Take Away: JavaScript frequently asked questions.
KB100168
Q. What is JavaScript?
A. JavaScript is a platform-independent, event-driven, interpreted programming language developed by Netscape Communications Corp. and Sun Microsystems. Originally called LiveScript (and still called LiveWireTM by Netscape in its compiled, server-side incarnation), JavaScript is affiliated with Sun's object-oriented programming language JavaTM 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 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.
Q. How is JavaScript syntax like C / C++?
A. 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.
Q. How do I protect my javascript code?
A. In the main you don't, as the language is ran from source, you need to deliver the source code, with JScript, there is the Script Encoder (see MSDN) but this is nothing more than obfuscation in effect, disabling the Right Mouse button, also achieves nothing to protect your script in a web browser.
Your code is likely protected under copyright laws. See:
Q. How do you specify the browser size of a window in a link?
A. You can do this using JavaScript. Here is an example: