Beginning Javascript Course

What is Javascript?

It is important to know, before we go any further, exactly what javascript is ( and is not ). To begin with, JavaScript IS NOT the same as JAVA. JAVA is a programming language developed by Sun Microsystems.

The term "JavaScript" appears to have origionally been a marketing ploy. At first, Javascript was called LiveScript. JavaScript ( or JS) was the name given it to boost sales and usage ( something about name recognition ).The two languages can, be used together, along with PSP, CSS, and several other languages, but this course is not designed to be that advanced. We will discuss its use with HTML, but that is the extent of the course.

What Prior Knowledge do I need?

This course is designed to provide an introduction to the JavaScript programming language. It is assumed that you have no prior knowledge of programming, however it requires some HTML knowledge, because JavaScript is to be embedded within an HTML document and to be interpreted by a web browser. If you do not already know HTML, it is suggested that you take a short course in HTML, like the one covered here

Whenever writing a JavaScript script - you need to use tags, much like you would with HTML. A JavaScript program is detected by the web browser, when inside an HTML page it sees the following tags:

<script language="JavaScript"> </script> .

JavaScript programs can be placed anywhere within an HTML document, however it usually goes after the </title> and before the </head> tags like this:

<head>
      <title>
          Title of your Web Page
     </title>

     <script language="JavaScript">
          Your JavaScript code goes here....
     </script>
</head>

Keep in mind while doing this course, though that while scripts may be placed anywhere in the document (as may be found necessary), the general rule of thumb is to place it at the top if at all possible, so it is easier to find, and it loads and runs faster there.

Alert Box



Ok - Let's get things started. Most computer languages courses begin with a way for you to reach out and touch someone. They teach you the basic "Hello World" program. In BASIC, it would be something like:

10 Print "Hello World"
20 END


In HTML, (which is considered more of a scripting language than a programming language), it would be a little more complicated:

<HTML>
  <BODY>
    HELLO WORLD!
  </BODY>
</HTML>


***Note - Code in BLUE is JavaScript code. Code in green is some other programming language

An "Alert Box" - sometimes called a "dialog box" or simply a "popup" - is a box that pops up on the screen - over the active window, to let the user know that something may be wrong. The alert() is used to display a box on the screen with a message of your choosing. In order to close the box and continue, the user must click [OK].

It's coded like this:

<script language="JavaScript">
     //the line below makes an alert box pop up
     alert("This is an Alert Box!");
</script>


Alert boxes come in handy to give some message to the user, such as if they neglected to fill in an important field in a form. They can also be an invaluable troubleshooting aid. For example, if you get some kind of error, you can insert an alert to find out if the error occurs before the alert - or or after your it. This can be very helpful if you are having problems, and can't figure it out just by looking at your code.

Let's look at the above code closely.

The first part of the program is:

<script language="JavaScript">

This tells the web browser that the coming commands are not HTML tags, but rather JavaScript. In this manner, the browser knows how to interpret and handle the code.

Next comes a comment statement.


     //the line below makes an alert box pop up

You should recognize these from HTML. Just like in HTML, the double slash "//" is used to preceed a comment, and everything following them to the end of the line will be ignored by the computer. The next line, though, is back in play.

If you wish to comment out multiple lines, or perhaps - large sections of code - (again for troubleshooting purposes) it can be accomplished like so:

/* Assume this is a very
large section of editorial
information explaining how the
code is supposed to work, or
giving credit to the person who
took time out of their life to
write it */


If you've done much HTML (or any programming language) coding, you probably realize how important comment statements are. If you haven't - rest assured you will find them invaluable for documentation. It helps others understand what you did, and can help immensely when you are trying to troubleshoot your code. It can be helpful to use them to separate sections of code from one another.

Also, keep in mind that not everyone viewing your page may have the latest and greatest of hardware/software to view your page. As a standard practice - JavaScript scripts should be "commented out" for the benefit of systems that don't support JavaScript. Below is a common method for doing this:


<script language="JavaScript">

<!-- The below code is JAVASCRIPT, and will be ignored by some browsers
alert("In addition to the basics of javascript - This 1st page will teach you how to make those ANNOYING pop-up boxes that everyone hates! (And most browsers will block nowdays).");
// END of JAVASCRIPT code -->
</script>

The <! is a comment line code in HTML, but not in JavaScript. So the Web Browser reads this as a simple comment, and ignores it until it sees the > at the end. If however, the system is JavaScript enabled, it will read the rest of the code and process it as normal. Also the double slash "//" before the "--end of HTML comment-->" is done so JavaScript doesn't read the closing HTML > as an error.

Editorial Notes on the use of Multiple Alerts

While it is entirely possible to generate a series of alerts popping up one after another, it is quite annoying. It can also be a turnoff to all your web site viewers, and can really tick people off if it is done maliciously. As such - many search engines look for pages that do this and BAN them from search engine placement - just like they would any page that they knew or could detect contains a malicious virus. That being said - here's how it works - purely for educational purposes. I'm certain, though, that none of you would EVER do this... right?

<script language="JavaScript">
      alert("Yet Another Annoying Popup!");
      alert("Yet Another Annoying Popup!");
      alert("Yet Another Annoying Popup!");
      alert("Yet Another Annoying Popup!");
      alert("Yet Another Annoying Popup!");
      alert("Yet Another Annoying Popup!");
      alert("Yet Another Annoying Popup!");
</script >


On The Following Indicator...
( GREEN will indicate your current location)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

[ ElectronicsTheory.Com ]


THINK FREELY!  Keep Electronics Education Free for the masses by buying form the EE store!




This Course was written by Ray Dall © All Rights Reserved.
This page and all it's content Copyright, Trademarks, Intellectual Properties
and other legal issues 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Ray Dall.
All Rights Reserved.
And for what it's worth... this page was last updated HexDate 01-11--7D1

VISITORS:
Add Me!