Not to be confused
with the programming language Java by Sun. If its Java and
Java applets you are looking for please see the Java
tutorials. Those of you who opt
to do both Java and JavaScript tutorials are going to notice the
two have more similarities then just their names. Java is more
tightly written and fussier then Javascript as JavaScript is a
loosely written language. Don't confuse them they are in fact
very different even with the similarities. Your
first step is to learn HTML if you are not literate in HTML
please visit our HTML tutorials before attempting to proceed
or you will only make your melon ache. In all my tutorials for
beginner programmers knowledge of HTML is assumed and expected
in order to get you started on learning to think like a
programmer and forms the foundation as your first computer
language to make learning the rest easier. JavaScript
was originally designed for Netscape navigator. Its an
object based language and trademarked by Netscape.
Microsoft followed suit and developed Jscript their
trademarked clone that was designed for Explorer. The two are extremely
similar but each has components the other doesn't to make it attractive
for programmers to favour one or the other . Pick me pick me!
Virtual politics. My advice is to try when you can to stick to
things that are compatible in both Netscape and Explorer
whenever you can. The
Programmer has two options when using JavaScript. You can
embed it directly into the HTML or you can link to a .JS
file. If
you are linking externally you would call it up like this in
your HTML
<script language="JavaScript" src="lamerssuck.js">
</script>
or to embed the
script it would look like this
<script language="JavaScript">
<!--
document.write("Lamers Suck!");
//-->
</script>
How you choose to go
about it is really up to you both have their benefits.
embedding the file is quick and easy, linking it makes it
harder for knobs to rip off your code if you want to protect
it. Another advantage to linking to it is that it leaves your
HTML easy to navigate through when you are editing instead of
crowding in all the JavaScript. I do a little of both
depending on my mood and situation. If
you are going to use JavaScript the best place to start is
learning what the different parts mean. Lets go over that now.
No you wont fully grasp this if this is your first time
learning about JavaScript but read it anyways so we can start
to build a foundation here.
Variables
|
Refer to a
changeable value.
|
Operators
|
Can be used
to compare values or calculate.
|
Expressions
|
A combination of
variables, operators, and statements which call up
some result. In English language this would be the
equivalent of a sentence.
|
Statements
|
JavaScript
statements may take different forms. You should separate
statements with semicolons for sanities sake but you don't
have to unless you put more then one statement on
the same line. In the English equivalent , a
statement pulls things together into a paragraph with
"sentences" ending in a period (semicolon).
|
Objects
|
Objects are a crucial
part of JavaScript. they may carry several properties
which act like variables reflecting a particular
value. |
Functions and
Methods |
A JavaScript
function is quite similar to a "procedure" or
"subroutine" in other programming languages. A
function performs some action. A method is a
function contained in an object. |
scope |
When you assign a
new variable to a value, you must consider scope.
A variable can be scoped as either Local or Global |
Type |
JavaScript categorizes
data into several possible types. hang on to your melon
now here we go....
Numbers
|
Integer and
floating-point numbers.
- Integers can be
positive, 0, or negative or in the form of a
decimal ,hexadecimal and
octal A decimal integer consists
of a series of digits without a leading 0 . A
leading 0 on an integer indicates it is
in octal; a leading 0x implies
hexadecimal. Hexadecimal integers can include
digits and the letters a-f. Octals can
include only the digits 0-7.
- A floating-point
number can hold a decimal point, an
"e" , which is used as "ten to
the power of" in scientific notation or
it can hold both an "e" and a
decimal at the same time.
|
Booleans
|
The
possible Boolean values are true and false. |
Strings
|
Strings are
designated by single or double quotation marks.
"Lamers Suck !" har har |
|
|
Null
|
no
value at all. |
Undefined
|
A value
that is undefined is a value held by a
variable before a value has been assigned to
it. |
|
Ok that's our
introduction and enough for one lesson. stay tuned for more.
Well go into more detail on all of these and put them into
practice in our subsequent lessons. |