www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons First JavaScript Code Example Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
Lesson 28
Lesson 29
Lesson 30
Lesson 31
Lesson 32
Lesson 33
Lesson 34
Lesson 35
Lesson 36
Lesson 37
Lesson 38
Lesson 39
Lesson 40
Lesson 41
Lesson 42
Lesson 43
Lesson 44
Lesson 45
Lesson 46
Lesson 47
Lesson 48
Lesson 49

In the previous lesson we learned about the basics of JavaScript. We learned that JavaScript is a browser scripting langauge, used to make our webpages lively and interactive.

In this lesson we will continue exploring this amazing programming langauge. Please note that throughout this tutorials we will be using the terms programming / program and scripting / script interchangeably.

Here is our first JavaScript code example:

<html>
<body>
<script type="text/JavaScript">
<!--
document.write("Pickatutorial.com JavaScript tutorial!")
//-->
</script>
</body>
</html>

The Output of the above code will be:

Pickatutorial.com JavaScript tutorial!

Lets examine the above code to see how did it produced the result above. It is assumed that you are already familiar with html. In the above code after the <body> tag, we have included the <script> tag. This tag is an indication to the web browser that whatever follows is not simple html, but is some sort of script and it has to be handled differently. The type attribute of the <script> tag has beed defined as "text/JavaScript", which means that the script is written in the JavaScript programmin language.

Note that we have written the JavaScript code inside the optional html comment tag <!-- //-->. We do this just for the compatibility purposes, in case a browser does not support JavaScript. You may have also noticed that the comment tag ends with //-->, unlike the regular html comment tag. This is done so as // is used to start a single line comment in JavaScript.

The actual output is done by the following line of code:

document.write("Pickatutorial.com JavaScript tutorial!");

The above line of code calls a function document.write() that writes the words "Pickatutorial.com JavaScript tutorial!" into our html document. We can use this function to output text, html or both.

Functions will be discussed further in one of coming lessons.

Unlike Java and C++ we do not need to put a semicolon i.e. ; to terminate our line of code. However if you like you can use it in your code. It only becomes necessary only when we need to write more than one JavaScript statements on a single line.


Next >>> Lesson No. 3: Adding JavaScript Code





Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.