Learning JavaScript Basics

Background

Before we get started I would like to just inform you a bit on the background of JavaScript. In 1995, JavaScript was developed by Netscape Communications Corp (The same company who build the Netscape Navigator). At first, was referred to as LiveScript. Netscape decided to change its name to JavaScript because of its relationship with Java.

Also, JavaScript does not require any special software or tools to execute. In fact, all you're going to need to get started coding is notepad and a browser. Even if you use a browser like Opera or Mozilla FireFox, they will recognize JavaScript in web documents.

The definition of JavaScript is: A scripting language that has the ability to combine HTML and other elements from a programming language all in one package. So JavaScript is as flexible as PHP. In PHP, you can simply jump in and out of HTML. This is pretty much the same with JavaScript. You will see exactly what I mean once you read on through the tutorial.

Once you begin coding in JavaScript this will always be your first line:

This first line of code is going to tell your browser that you will be using JavaScript. Once you have finished coding your document, you will use the following line of code that will tell the browser that you're done using JavaScript at that time.

*All statements in JavaScript will be between the <Script> and </script> tags. Also, all statements in JavaScript must end with a semi-colon (;).

Pretty simple? Programmers say that JavaScript is one of the easiest languages to learn, and it is a great starting point for aspiring programmers. Another reason it is a good place to start is because the JavaScript syntax is quite similar to C. So once you have learned JavaScript, learning C will be much easier.

EXTERNAL LINKING

Now if you're going to use JavaScript in your html document, and you do not want it all cluttered up, then the is a way to hold the javascript in a separate file, and link to it. This would save some space in your html document and could also keep you on track. The following code below indicates the way to link to your external javascript document:

As you can see from the example above, your external javascript documents will need the ".js" extension. So if you decide to create your JavaScript outside of your html document, remember to save your script with a ".js" extension.

*Also just a little extra information, your external JavaScript file does not need to include the <script> and &lt/script> tags

COMMENTS

In every programming language, you can add in comments with your program. Comments are lines of code that will not be executed with the rest of the program. It is wise to indicate comments because It can help you remember what you're doing yourself if the project is quite big. Also, it can be helpful for others that may see your program. This can help them learn to code themselves.

Now, there are several different ways to use comments in JavaScript. JavaScript recognizes single line comments, and multiple line comments. If you were to insert a comment that would only span one line, you will use the double slash: //.

example:

To enter multiple line comments, or comments that are going to take up more that one line (like a paragraph) you will use the /* and the */ characters.
example:

Now that we've covered that, lets go ahead and move on to Variables and Constants.