Site hosted by Angelfire.com: Build your free website today!


Making Sense of JavaScript

JavaScript is a client-side programming language meant for use on the Web. In other words, when a visitor downloads a page with JavaScript in it, that script is ran on the visitor's computer inside his or her Web browser.

What JavaScript can and cannot do

JavaScript can create pop-up windows and cause text or a graphic image to change during a mouse rollover. It also includes commands that allow you to control the content being displayed in the browser. It can be used to open new documents in a window or to return to a previously visited document. JavaScript is also very handy for working with frames and content in groups of related windows since it can be used to pass information between windows and frames. JavaScript is also commonly used for creating interactive menus and interactive quizzes. JavaScript can be used to process data as well as validate form data (i.e., mathematical computation, generation random numbers, performing other typical computational actions, et cetera). It allows one to add scrolling messages, data input forms and animation to a Web page. JavaScript can even be used to pass information to Java applets within the browser window. This allows properties to be set dynamically when the applet is executed.

JavaScript has no graphics capabilities, no networking support and no access to the contents of your computer. It cannot access files on the server, handle file uploads or gather any information about the user (i.e., email address, IP address, et cetera). JavaScript also cannot read or write files. In other words, JavaScript cannot create stand alone applications or applets. It cannot create multiplayer games or get data from a server database. It cannot submit credit card-based purchases for authorization and payment.

JavaScript vs. Java: What's the difference?

Despite, the fact that both JavaScript and Java both resemble C in their syntax, JavaScript is not Java. JavaScript (originally named LiveScript) is a primarily client-side scripting language from Netscape that is only marginally related to Java, a network application language created by the Sun Microsystems. It should be noted that JavaScript can communicate with Java, which is a useful feature, but they are not the same thing. JavaScript resembles Java but does not have Java's static typing and strong type checking. The difference is that Java was built as a general-purpose object language, while JavaScript is intended to provide a quicker and simpler language for enhancing Web pages and servers. In contrast to JavaScript's runtime system based on a small number of data types representing numeric, Boolean and string values, Java's compile-time system of classes is built by declarations. JavaScript can be used to fully control Netscape and Microsoft Web browsers, including all the familiar browser attributes (see JavaScript Resource Center for additional information). Java is used to create applets or stand-alone applications whereas JavaScript lacks this capability.

The advantages and disadvantages of using JavaScript

Advantages of JavaScript:
Disadvantages of JavaScript:

The structure and use of variables, including naming conventions and variable types

In order to use variables, you declare a variable and given a value to that variable. When declaring a variable, use the keyword VAR. An example of a code that utilizes variables is a follows: var page= 0. Variables must start with a letter or underscore and subsequent characters can also be digits (i.e., 0, 9, et cetera) or letters (i.e., A, a, Z, z, et cetera). There should not be any punctuation or spaces within the variable name. Please note that JavaScript is case sensitive. In other words, JavaScript interprets myvar and myVar as two different names (See JavaScript Variable Chart for examples of valid variables). Also, avoid naming variables with reserved words, which are predefined words in JavaScript with a specific meaning (See JavaScript Reserved Words for more information). In JavaScript, all variables have either a global and local scope. Global scope means that the variable is defined everywhere in the script and by extension, everywhere in the document containing the script. For example, all predefined variables and objects have a global scope. Local scope means that the variable is local to a function. In other words, it only exists within the function for the duration of the function. Please noted that JavaScript does not have a block scope.

Javascript supports several types of variables (See JavaScript Variable Chart for more information about variable types), which are strings, objects, null, undefined, numbers and boolean (true or false). Strings are delineated by single or double quotation marks. Number variables include integer and floating-point numbers. Integers can be positive, 0, or negative; Integers can be expressed in decimal (base 10), hexadecimal (base 16), and octal (base 8). A decimal integer literal consists of a sequence of digits without a leading 0 (zero). A leading 0 (zero) on an integer literal indicates it is in octal; a leading 0x (or 0X) indicates hexadecimal. Hexadecimal integers can include digits (0-9) and the letters a-f and A-F. Octal integers can include only the digits 0-7. A floating-point number can contain either a decimal point, an "e" (uppercase or lowercase), which is used to represent "ten to the power of" in scientific notation, or both. The exponent part is an "e" or "E" followed by an integer, which can be signed (preceded by "+" or "-"). A floating-point literal must have at least one digit and either a decimal point or "e" (or "E"). An object is a complex data type that is made up of a collection of data elements (i.e., var x = new Object();). See JavaScript Objects for more information about and examples of Objects. The possible Boolean values are true and false. These are special values, and are not usable as 1 and 0. In a comparison, any expression that evaluates to 0 is taken to be false, and any statement that evaluates to a number other than 0 is taken to be true.

The difference between variables and literals

A literal is a value that can be assigned to a variable. Literals are not variables! They are fixed values that the designer literally provides in his or her application source. In other words, literals are what they are and do not change. Several types of literals (i.e., integers, floating-point numbers, strings and Boolean literals) in JavaScript correspond to the variable types. Variables represent values stored in memory for use by the script. The difference between the two is a literal evaluates to itself whereas a variable evaluates to the value assigned to it. When literals and variables are linked by operators, the resulting statement is an expression. However, a literal or variable may be a valid expression, they are not expressions that do anything. Expressions that actually perform a function are created by linking simple expressions together with operators.

How to set up expressions, including the rules for the order of precedence

The simplest form of expression is a literal or a variable. An expression is any valid set of literals, variables or operators that is used to evaluate to a single value (i.e., a number, a string, a logical value, et cetera). An operator combines simple expressions together into more complex expressions by creating relationships between the simple expressions that can be evaluated (i.e., 2 + 9). The numbers 2 and 9 are each valid expressions whereas the plus sign (+) is an operator. The equation 2 + 9 is also a valid expression, whose value is 11. There are two main categories of expressions: assignment operators, expressions that assign a value to a variable and operators, expressions that simply have a value. The assignment operator (=) is a binary operator that assigns a value to the left operand (usually a variable) based on the value of the right operand (such as FirstName = "Erik" or x = y * 7).

Precedence refers to the order of evaluation when an expression contains several operators. This determines the order the expressions are applied when evaluating an expression. The rules for the order of precedence are as follows: operators are evaluated in the order of their precedence, operators of same precedence are evaluated based on their associativity, parenthesis are used to override precendence, and Parenthesized expressions are evaluated from the innermost to the outermost set of parenthesis. Essentially, an expression operates by taking the values to the right-hand side of the equal sign, performing the arithmetic operation and then storing the result in the variable. If the expression contains literals, variables or operators of the same level of important then the computer will evaluate the expression from left to right. In JavaScript, multiplication and division have higher precedence than addition and subtraction.


Valioso Perla Web Designs
E-mail: ValiosoPerla@hotmail.com

Return to IST 239 Project Index
© Copyright 2004 by Valioso Perla Web Designs. All rights reserved.