Javascript is not the same thing as Java. Javascript is a programming language used to make web pages interact able, while Java is a completely different programming language that is independent of html and web browsers.
We will stick with Javascript, although when you learn the basic components of a programming language like Javascript, you actually learn the foundation of several programming languages. Many elements found in Javascript are also found in PHP, Action script, Java, and even C++.
Object Oriented Programming is a way of progamming where code is written independent of each other, and trigured when and where ever it is called. It is usefull because you can write a line of code once, and use it over and over again.
a Javascript applet may be a couple lines of code, or it could include several pages of code that reference each other in order to work. It all depends on what you are trying to do with it.
To include javascript code in an html file you wright the code in between <script></script> tags.
But there are other codes that use the <script></script> tags, so you need to type it like this: <script type="text/javascript">
A variable is a name associated with a value. A variable can be created by typing:
var name = value;
For instance you could type <script> var best-computer="Mac";</script>. Of course this code would have no noticeable affect.
The value of a variable may be set to several data types; Strings, integers, booleans, null and undefined. If no value is assigned the value is undefined. The other three are discussed later.
Operators are often symbols you would find in a math equation; such as =, +, -, but there are many more.
Strings are "strings of text" or a combination of letters. They may form recognizable words or phrases, but to javascript, they are just letters. In Javajcript strings are always shown in "quotes". You would create a string like this; var nonsense = "fjfdkdh";
Integers are whole numbers. And Javascript recognizes them as whole numbers. by combining integers with operators you can perform math equations.
A boolean is a value of true or false. If you type var a = true; a would hold a bolean value of true.
Arrays are one of the most usefull building blocks of Javascript. An array holds multiple values that are accessed sequentially, or in order. Table data is often stored in arrays, and then dynamically placed in <table> HTML tags. You can create an array by assigning an array to a variable like this: var car_array = new Array("Mustang", "Focus", "Camaro", "Civic", "Accord", "Camery");
Statements are used to create conditions. A common Statement is an if statement, which looks like this. if(a == true){document.wright(car_array);}
Functions are an important part of programming. A function is a command or a set of commands that are performed when the function is called. A function is usually called by an event such as a mouse click, a mouse move or a key stroke. you can also manually call a function by assigning it to a variable. Here is an example of a function:
function write_nonsense() { document.write(" " + nonsense);
}
var call_function = write_nonsense();
Classes are used in Object Oriented Programming and more advanced programming. This site will not explore Classes. For more information on Javascript and classes, try HTML Goodies
Objective 9: type Javascript
Read About Javascript. Type the examples found on this page in an html document. Remember, Javascript is written in between <script> tags. Hint 1: You may need to combine examples to get a result. Hint 2: You may not get how all of this works yet. That is OK. That will come later.