Skip to main content

introduction about JavaScript

Hi everyone, I’m Chamini prahskthi from SriLanka.
And….
This is the beginning of my JavaScript tutorial. Hope you will interest to learn JavaScript from beginning. I hope to give you step by step guide to be expert about JavaScript.
OK,
Do you know???
JavaScript is a client side developing language. JavaScript can be used to control the web browser. So, Normally JavaScript is use for validations.
 like,
Check if you have enter and valid email address.
Also JavaScript is use to perform events like button clicks.

So let’s move to the lessons. For this developing purpose you just need a text editor like Notepad++, sublime text etc.
Here I’ll use Notepad++ for demonstration purposes.
First of all I must tell you this. You must have very simple html knowledge for learn JS (from here I use short form JS for JavaScript).
Ok let’s move on…
JS is used with in HTML tags. Normally it used within <head> tags. But it is okay to use anywhere in HTML source code. But the standard way is this. When you began to write a JS code within HTML code, what you have to do first is put <script> tags.
It is like this

                                    Figure 1
Do you know why I have put ,
<script language =”javascript” type=”text/javascript”?
Here the word 'language' defines what scripting language we are using and type means the media type we are using.

So, for the first commencement I wish you show this kind of a code set.
Example one

Figure 2

OK I save this code as string.html. Then run the program and following image show what I show after run this.

                                             Figure 3

So, let’s clarify what is in the figure 3. You already know that js is begin with <script> tags.
After beginning of this tags I have write a function document.write .It is a predefine function in js to write strings in our web page. And other special this is comment that I have put within js code. You can use /* …*/ for multiple line comment and // for single line comments in js. (Just like Java)

Ok let’s move on another example.
Example two

                                                                 Figure 4
Result of this source code:

                                             Figure 5

So, I have done something different here. I crated js function within the js code and called it in the html code.
The function show an alert. Here when you want to create a js function you need to write basically
Function function_name(){
Function body
}

That’s all…
It is easy. Isn’t it?
So here I used alert() function. When an alert function runs, it shows an alert in the web browser. In addition to that I used button in the web page and I called that js function after click the button. (it is like an event performing as I mentioned before.

So I think it is enough for today and I will meet you with my next js tutorial with another new lesson.

Thankyou…

Comments