Understanding JavaScript part - 1 (getting started)

AID: 9555
  • Status: Published

1420 points

  • Byd4durvesh
  • TypeTutorial
  • Posted on2012-02-06 at 05:53:23
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big article at a time. You may also get in confusion with it and complexity is also high. So lets learn JavaScript we will together will have lots of fun and good company. :-)

Things you should know before you start learning JavaScript


To get started with JavaScript, you should have a basic, comfortable working knowledge of:
  • Basic HTML (Hyper Text Markup Language)

  • Basic CSS (Cascaded Style Sheets)

If you do not have a comfortable working knowledge of these topics, I suggest you read up on them before you continue.

If you are a programmer then, great! But if you not, then even better!


      Everyone is welcome in JavaScript. We will be learning JavaScript from scratch. So, if you know  another programming language, you may want to skip some of the basic topics, but I  suggest you resist that temptation because it may cause you confusion ahead. For those who are new to programming, you're in the right place.

"NO PROGRAMMING KNOWLEDGE IS REQUIRED TO GET STARTED WITH JavaScript".



History


     JavaScript was formed by Netscape developers in 1995. They named it as "LiveScript" that time. But in same period Sun's java was come into fame sun and Netscape collaborate and after that it is term to be as a JavaScript. Lets not go in detailed of that and lets move on to next topic that is,

Introduction


      JavaScript is a client side scripting language i.e., it has a control of user. JavaScript is a dynamic language and gives lots of interactivity to the websites. Unlike HTML, JavaScript can validate user forms , run on some events, and is user friendly. The main point to notice is that JavaScript is DYNAMIC while HTML is STATIC.

What JavaScript Can Do


  • Give user friendly interactivity.

  • Can validate data on data.

  • Can do certain things using event-handlers.


What JavaScript Can't Do


  • JavaScript cannot write anything on system files.

  • It can not be use to enter in DB (database) or change it.


OK, so lets quickly move on to...

Getting Started


       Let's get start with JavaScript. You will need text editor to write JavaScript code. if you are a Windows user, then I will recommend you to use notepad++ but if you are a Mac user, then you will like BBedit. But, it does not matter what editor you use, the output you will get will be the same in all. Also make sure your browser supports JavaScript, and it is enabled. If not, then you can enable it from preferences tab under setting.Check it out this information about "How to enable JavaScript in browsers.
  So lets see your first JavaScript code
<script type='JavaScript'>
alert("Hello Expert-Exchange");
</script>
                                    
1:
2:
3:

Select allOpen in new window


Feel Free to copy above code and paste it in your HTML document's head tag, and check what happens when you run this code. The browser will pop up a box, which will say: "Hello Experts-Exchange".
       By now, you have certainly noticed that JavaScript is enclosed in <script></script> tags. While you may place JavaScript in anywhere in HTML document, you should normally write JavaScript in the <head> tag whenever possible. Check the minor differences by writing JavaScript in head tag and body tag. You can also embed externally by using 'scr' attribute in Script tag, like:
<script type='JavaScript' src='main.js'>
//some code
//some more code
</script>
                                    
1:
2:
3:
4:

Select allOpen in new window


  Embedding files is very much easy and save lot of time.  So, Let's check below steps to embed your first JavaScript program in your .html document,

Steps to implement JavaScript using embeded technique,



1

Open / Run editor. (whichever editor you have) like notepad++


2

Write you HTML program with script attribute.


<html>
<head>
<title>Simple Page</title>
<script type="text/javascript" src="alert.js">
</script>
</head>
<body>
	<h1>Simple HTML Page</h1>    
    	<p>
    	This is a very simple HTML page.
    	</p>

	<p>It's about as basic as they come. It has:<p>

	<ul>
		<li>An H1 Tag</li>
		<li>Two paragraphs</li>
		<li>An unordered list</li>
	</ul>
</body>
</html>
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:

Select allOpen in new window


3

Then go to file > save > type any name like sample.html


4

Open / Run editor


5

Type your JavaScript code


alert("Hello, World");
                                    
1:

Select allOpen in new window


6

Then go to file > save > type any name like alert.js


7

And finally run your sample.html file.


8

Make sure both .js and .html files are in same directory.


9

Same you can do with your exercise too.



  • I have attach both alert.js and sample.html files. So please download it and save both files in same folder and see the output.It will help you to get better experience.

 
But if you want to try it internal technique then follow this steps,

Steps to implement JavaScript using internal technique,



1

Open / Run editor. (whichever editor you have) like notepad++


2

Write you HTML program with script attribute.


<html>
<head>
<title>Simple Page</title>
<script type="text/javascript">
alert("Hello, World");
</script>
</head>
<body>
	<h1>Simple HTML Page</h1>    
    	<p>
    	This is a very simple HTML page.
    	</p>

	<p>It's about as basic as they come. It has:<p>

	<ul>
		<li>An H1 Tag</li>
		<li>Two paragraphs</li>
		<li>An unordered list</li>
	</ul>
</body>
</html>
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:

Select allOpen in new window


3

Then go to file > save > type any name like sample1.html


4

And finally run your sample.html file.



  • Check sample1.html file which is attach to the article

Let's now do some practice exercises so you can perfect your knowledge and experience of JavaScript:

Exercise

  • Make a alert box in JavaScript popping "My first program in JavaScript." using internal technique

  • Make a alert box in JavaScript popping "My second program in JavaScript." using embedded technique

  • Create one HTML document add some HTML tags then make alert box and check what happens when you placed it in head tag and what happens when you place it in above </body> tag.(do not forgot to add script tag with alert box.)


     After you complete your first JavaScript program, you can move on to the next lesson where you will learn how to create a variable, and how to store any value in your JavaScript program.Lot more to come, please do not miss it!

Please vote 'YES' if you like this article, or share it to your friends using the share buttons to the left.

If you have questions, feel free to ask them in the comments below.

Please read next part of this series Understanding JavaScript part - 2 (Introdution to variables and pop-up boxes)
  • alert.js
    • 22 bytes

    externally embeded alert box

  • sample.html
    • 376 bytes

    example one using src attribute

  • sample1.html
    • 385 bytes

    example 2 with internal alert box.

Asked On
2012-02-06 at 05:53:23ID9555
Tags

Javascript

,

learn javascript

Topic

JavaScript

Views
687

Comments

Expert Comment

by: DrDamnit on 2012-02-07 at 11:23:53ID: 42220

If you've worked with him before, do you want to take it?

Expert Comment

by: mikeplastic on 2012-02-29 at 12:59:56ID: 44415

Nice article, I know more now than I did before.  Thank you for your effort.

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top JavaScript Experts

  1. leakim971

    511,289

    Sage

    2,168 points yesterday

    Profile
    Rank: Genius
  2. mplungjan

    291,279

    Guru

    2,800 points yesterday

    Profile
    Rank: Savant
  3. nap0leon

    195,491

    Guru

    0 points yesterday

    Profile
    Rank: Sage
  4. Proculopsis

    182,948

    Guru

    0 points yesterday

    Profile
    Rank: Sage
  5. COBOLdinosaur

    157,309

    Guru

    0 points yesterday

    Profile
    Rank: Genius
  6. chaituu

    130,684

    Master

    0 points yesterday

    Profile
    Rank: Sage
  7. Ray_Paseur

    130,217

    Master

    330 points yesterday

    Profile
    Rank: Savant
  8. tommyBoy

    125,345

    Master

    0 points yesterday

    Profile
    Rank: Genius
  9. StingRaY

    114,318

    Master

    0 points yesterday

    Profile
    Rank: Wizard
  10. DaveBaldwin

    80,081

    Master

    336 points yesterday

    Profile
    Rank: Genius
  11. ansudhindra

    79,054

    Master

    2,000 points yesterday

    Profile
    Rank: Wizard
  12. ChrisStanyon

    62,768

    Master

    800 points yesterday

    Profile
    Rank: Sage
  13. hielo

    61,266

    Master

    0 points yesterday

    Profile
    Rank: Savant
  14. HainKurt

    59,030

    Master

    0 points yesterday

    Profile
    Rank: Genius
  15. BuggyCoder

    54,739

    Master

    0 points yesterday

    Profile
    Rank: Sage
  16. mroonal

    54,339

    Master

    10 points yesterday

    Profile
    Rank: Sage
  17. tagit

    54,093

    Master

    1,600 points yesterday

    Profile
    Rank: Genius
  18. gurvinder372

    52,824

    Master

    10 points yesterday

    Profile
    Rank: Genius
  19. basicinstinct

    52,586

    Master

    0 points yesterday

    Profile
    Rank: Genius
  20. JonNorman

    45,158

    2,200 points yesterday

    Profile
    Rank: Master
  21. Lalit-Chandra

    44,420

    0 points yesterday

    Profile
    Rank: Master
  22. xmediaman

    36,450

    3,800 points yesterday

    Profile
    Rank: Guru
  23. kozaiwaniec

    33,100

    0 points yesterday

    Profile
    Rank: Guru
  24. Kravimir

    32,700

    0 points yesterday

    Profile
    Rank: Genius
  25. designatedinitializer

    32,300

    0 points yesterday

    Profile
    Rank: Master

Hall Of Fame