Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » JavaScript » Basics of JavaScript - Part 1

Basics of JavaScript - Part 1

This article will explain, basics of JavaScript programming including differences between Java and JavaScript and HTML, history, functions, how to write JavaScript, features, how to use on web page like external .js file etc.

Author Rank :
Page Views : 1755
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


What is JavaScript

JavaScript is an object-oriented scripting language used to enable programmatic access to computational objects within a host environment. Although also used in other applications, it is primarily used in the form of client-side JavaScript, implemented as part of a web browser, providing enhanced user interfaces and dynamic websites. JavaScript support is built right into web browsers. Provided that the visitors to your site are using web browsers that support JavaScript (most do) and have JavaScript enabled (it is by default) then your JavaScript will run.

Differences of JavaScript and Java

There are many differences between Java and JavaScript language as

JavaScript Java
Interpreted by client mainly Compiled on server and changes it in HTML and user gets only HTML coding as in ASP, PHP etc languages. Because user's browser only reads HTML and JavaScript coding.
Object-based language because it has no class or inheritance features Object-oriented and it has class or inheritance features.
It has no graphics capabilities It has high graphic capabilities
It can't read or write files It can read and write files
It has no networking support like can not let us to chat or communicate within network computers using bind(), listed() or send() properties It has all networking support

History of JS

When World Wide Web created in early 1990s all web pages were static. When we view the web page on internet we exactly saw what the page was set up to show. Netscape was the first to bring out a programming language that would allow web pages to become interactive - they called it LiveScript and it was integrated into the browser. The programming language called Java became very well known and so Netscape decided to cash by renaming the language to JavaScript what they have created for Netscape Navigator browsers. At the time Netscape Navigator was by far the more popular browser and so later versions of Internet Explorer implemented versions of Jscript and vbScript that were more and more like JavaScript. It is very big cause not to support all script commands by all the browsers. Although scripting language was too great to deal its future developments so in 1996 JavaScript was handed over to an international standards body called ECMA who then became responsible for the subsequent development of the language. As a result of this the language was officially renamed ECMAScript or ECMA-262 but most people still refer to it as JavaScript.

Function of JS

JavaScript is a client-side programming language meant for use on the web and when you request for any page on web script coding automatically runs on our computer because our browser have the ability to read JS coding. Client-Side scripting language means which runs on user's computer and Server-Side scripting language means, which runs on server computer from where the web pages are requested.

Where to write the JavaScript Program

JavaScript is an interpreted language and so no special program is required. Any plain text editor such as Notepad is quite satisfactory for being able to write JavaScript. That said, an editor, which colorizes the code to make it easier to see what is what makes it easier to find your mistakes. An editor named Komodo will be nice for to write JavaScript coding.

Difference between HTML and JavaScript

HTML and JavaScript are two completely different things. HTML is a mark-up language designed for defining static web page content. JavaScript is a programming language designed for performing dynamic tasks.

Features of JavaScript

There are lots of features as listed below:

  1. A Great Programming tool for HTML

    Professional Web designers are undoubtedly adept in using HTML because JavaScript is a powerful scripting language that helps HTML designers to effectively and interactively design websites and web pages in a very simple and efficient way.

  2. Handles Dynamic Effects

    JavaScript is such a powerful scripting language, which has features to achieve dynamic effects in web pages. Using the features available in JavaScript, the designer can decide to have dynamically placed text at run time.
     
  3. Browser Detection

    One of the powerful features of JavaScript is its ability to detect client side browser. Browser detection feature of JavaScript helps to achieve independent platforms. JavaScript can detect the type of browser the visitor is using and programmatically switch the page to show customised pages designed for different browsers. Thus by making use of browser detection feature of JavaScript, the designer gets better control over the browser.
     
  4. Time Savings

    JavaScript also has the feature of validating data submitted at the client level. This helps in saving the processing time of the server because JavaScript initially creates the validation on the client side.
     
  5. Interpreted Language

    It is an interpreted language, meaning that it can be used or executed with ease without pre-compilation.
How to use JS in web page

There are mainly two ways to use JS in web page:
  • Using JS commands within the web page with HTML coding
  • Using JS commands from external JS file

Using JS commands within the web page with HTML coding

We use to write all codes in a same page which has the extension .htm, .html, .php, .asp, .aspx, .cfm etc.

<html>
<head>
<title>TESTING JS</title>
<script language="JavaScript" type="text/javascript">
window.print()
</script>
</head>
<body onload="disco()">
    <div> This is the content to be printed. </div>
</body>
</html>


More examples

JavaScript in head

<html>
<head>
<script type="text/javascript">
function message()
{
alert("This alert box was called with the onload event");
}
</script>
</head>
<body onload="message()">
<p>We usually use the head section for functions (to be sure that the functions are loaded before they are called).</p>
</body>
</html>


JavaScript in HTML H1 tag

<html>
<body>
<script type="text/javascript">
document.write("<h1>Hello World!</h1>");
</script>
</body>
</html>


JavaScript in body

<html>
<body>
<script type="text/javascript">
document.write("<h1>Hello World!</h1>");
</script>
</body>
</html>


Using JS commands from external JS file(s)

To use JavaScript (.js) files in HTML page, we have to write all JavaScript coding in a file, which has exetesion .js, and remember not use opening and closing <SCRIPT> tags in .js files. Assume that we have myjava.js file which has some coding, without only <SCRIPT> tags. And now to use it in HTML file write the following code in HTML file

HTML file content

<html>
<head>
<script type="text/javascript" src="external.js">
</script>
</head>
<body onload="message()">
This text is from body
</body>
</html>


external.js file content

function message()
{
alert("This alert box was called with the onload event");
}

HAVE A HAPPY CODING!
 

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Abhimanyu Kumar Vatsa
http://www.itorian.com/about/
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Nevron Gauge for SharePoint
Become a Sponsor
 Comments
give reference by Nikhil On June 16, 2010
    You need to give reference from where you excerpted this article.
Reply | Email | Modify 
Re: give reference by Abhimanyu Kumar On June 17, 2010
Hello Nikhil..........

Thank you for your article reply.

As I am teaching the students of KSOU (Karnataka State Open University) for JavaScript and Web Designing (Paper Code-BS 32), this is my own notes. And I have released only its 5 parts still and many parts are under construction. I only referred the syllabus of KSOU not the book contents. I can proudly say that the entire content of my all Articles in this community are self developed not copied from anywhere else. You can check it out.


Well thanks for you Article reply.

Take Care of you.

Good Luck
Reply | Email | Modify 
Re: Re: give reference by Nikhil On June 20, 2010
Great, then post this in blogs as these'are basic concepts.

Cheers !!!
Reply | Email | Modify 

 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.