website promotion banner
eturnkeys
Your Ad Here
Web Programming  Home Web Programming JavaScript Learning JavaScript Basics
rss

Learning JavaScript Basics

Author: allsyntax.com More by this author
Browse Pages:  1  2  3  4  5 > >>


Java Script 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, JavaScript wasnt even called JavaScript, it 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:

<script langauge="javascript">

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.

</script>

*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 isnt it? 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 dont want it all cluttered up, then the is a way to hold the javascript in a seperate 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:

<script language="javascript" src="your_file.js">

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 </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 themself.

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:

//This would be a single line comment in JavaScript.

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:

/*Here is a multiple line comment in JavaScript. You can use this method if you would like to go into more detail on how a particular part of your program is coded.*/

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



print this page tell a friend subscribe to newsletter subscribe to rss
Rate this Material: Bad 1 2 3 4 5 Excellent
Browse Pages:  1  2  3  4  5 > >>

Add comments to "Learning JavaScript Basics"