Home Free Templets Works Mind Chiller Photo Gallery Family & Friends Links
 
 
   
     
           
           
           
           
   
Javascript Basics Part-1
     
           
   


Why Javascript

Javascript is mainly used for client-side scripting, that means , javscript can execute in the same page in which the user is currently working.

Warning: Some browsers does not understand JavaScript, and in some browsers user can disable javascript. In these cases your javascript code will not be executed.

The javascript code is written whithin the tags
<script Language="javascript">
</script>
Javascript syntax mostly resembles with c/c++ , so extra advantage to you if you know C.

Variable Declaretion : Variables are some memory address defined by programmers to store some values. In Javascript a variable is declared with the keyword "var" which is the datatype of the variable, then the variablename. A variable declared as "var" can hold any type of values like integer,float and String .

<script language="JavaScript">
var f_name; // Declare a variable named "f_name"
var l_name; // Declare a variable named "l_name"
f_name = "John"; //set the values of f_name and l_name
l_name = "Doe";
alert("Hello!" + f_name + " " + l_name); // show in a messagebox
</script>

Explanetion : Here we have declared two variables "f_name" and "l_name", and set their values to "John" and "Doe respectively. The next Line alert("Hello!" + f_name + " " + l_name); need some more attention.
In javascript, you can show messages in "MessageBox" using the statement "alert" or "window.alert", e.g., If you write alert("Hello') in JavaScript , then it will display the message "Hello" in a box with an "OK" button on the box. If you press "OK" button, the box will dissapear.
Now, in JavaScript , the "+" symbol joins two strings if it works on string and adds up two numbers if they are integers.
Thus , the statement
var i = 10 + 20;
will assign 30 to variable i. And the statement,
var i = "Hello" + " Howdi";
will assign "Hello Howdi" to i. Software geeks call it "string Concatination" ,so you will also call it the same.

Here, in our current example, the statement "Hello!" + f_name + " " + l_name" actually joins the string "Hello" with the value of the variable f_name, the joins a blank string with " ", then the value of the variable l_name.

Note : Like "alert()" another statement also comes handy in printing some value is
document.write();
Unlike, alert() box(which dissapers when you click "OK" button, "document.write()" writes the message permanently on the current HTML page. So, if you have written the code like this

<script language="JavaScript">
var f_name; // Declare a variable named "f_name"
var l_name; // Declare a variable named "l_name"
f_name = "John"; //set the values of f_name and l_name
l_name = "Doe";
document.write("Hello!" + f_name + " " + l_name); // display in HTML
</script>

Then you would get the result in the current HTML page.

Back to Tutorial Index page

Your comments are most welcome admin@koderguru.com