ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing

ExpertRating Home
ExpertRating Benefits
Recommend ExpertRating
Suggest More Tests
Privacy Policy
FAQ
Login
 
JavaScript Tutorial - Index
JavaScript Tutorial - Introduction to JavaScript
JavaScript Tutorial - Basic JavaScript Concepts
JavaScript Tutorial - Working with Operators and Variables
JavaScript Tutorial - How to work with Loops and Functions?
JavaScript Tutorial - How to work with Forms and Events?
JavaScript Tutorial - How to work with Objects?
JavaScript Tutorial - How to work with Browsers and Cookies?
JavaScript Tutorial - More about Objects
JavaScript Tutorial - How to validate Forms with JavaScript?
JavaScript Tutorial - Advanced Techniques in JavaScript
     

 
Online Personal Trainer Certification
Personal Trainer Certification (Spanish)
Six Sigma Certification
Find a Personal Trainer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Master Black Belt Certification
Six Sigma Green Belt Certification
Life Coach Certification
Lean Management Certification
Lean Six Sigma Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
Business Analyst Certification
SEO Certification
Online Business Writing Course & Certification
Baby Sitting Course & Certification
Time Management Certification
Health Club Management Certification
Medical Coding Certification
Medical Billing Certification
Business Analysis Course
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
Event Management Certification
Test Search by Job Title
Administrative Assistant Certification
Virtual Assistant Certification
  All Online Courses
   

   
   
   
   
   
   

   
  Home > Courses, Tutorials & eBooks > JavaScript Tutorial > Basic JavaScript Concepts
 

JavaScript Tutorial - Basic JavaScript Concepts

 
Page 1 of 1
 
Overview
 
In this chapter you will learn :
  • Basic concepts of JavaScript.
  • Location of the <SCRIPT> tag in an HTML document.
  • Writing a simple JavaScript program.

 

 

Basic JavaScript Concepts

JavaScript  is embedded into an HTML file. A browser reads the HTML files and interprets HTML tags, but the browser needs to be informed that specific sections of HTML code is JavaScript. The browser is given this information using the tags <SCRIPT>......</SCRIPT>. The browser will then use its built-in JavaScript engine to interpret this code.

Syntax
<html>
<head>
<Script Language = "JavaScript">
                          JavaScript code is written here.
</Script>
</head>
</html>

 

Note
If the Language attribute is left undefined then the default scripting language of Netscape is JavaScript, whereas Internet Explorer has VB Script as its default scripting language.

There can be three different locations where the script tag can be placed in the HTML document :

In the Head Section

As the head loads before the body, it is guaranteed that it is available when needed. Hence, it reduces the scope of errors.

Example
<html>
<head>
<Script Language = "JavaScript">
                      In this example, the script tag has been placed inside the head section.
</Script>
</head>
</html>

In the Body Section

Place the script tag in the body section if you want to generate certain content on the page when it loads.

Example
<html>
<body>
<Script language = "JavaScript">
                    document.write ("Here script tag has been placed inside the body section ");
</Script>
</body>
</html>

Note
You can place the script tag at both places, i.e., inside the head section as well as the body section.

 

In an External File

When you want to use the same script on different pages, you can use the external file. The advantage of using external file is that you don't need to rewrite it. External JavaScript file is saved with a '.js' extension.

Example
<html>
<head>
<Script = "myexample.js">  </Script>
</head>
<body>
</body>
</html>

Write your First JavaScript Program

Program
<html>
<head>
<title>My first program </title>
</head>
<body>
<Script Language = "JavaScript">
                document.write(" My first program ");
</Script>
</body>
</html>

Document is a part of Document Object Model (discussed later in this tutorial). Document refers to all the text and HTML elements between the two BODY tags. Write( ) is a method of Document. So the document.write is a standard JavaScript command for writing output to a page. The language attribute indicates the scripting language used for writing the piece of scripting code.

 
 
Summary
 

In this chapter you have learnt:

  • Writing JavaScript into HTML.
  • All JavaScript statements must be included in the <SCRIPT>...</SCRIPT> tag.
  • Different locations where SCRIPT tag can be placed.
  • Advantage of creating external JavaScript file.
 
 
Review Questions
 

Fill in the Blanks

  1. JavaScript is embedded between -------- tags of HTML.
  2. The extension of external JavaScript file is ---------.

Solutions

  1. SCRIPT
  2. .js

True or False

  1. <SCRIPT> tag should always be placed in the head section to reduce errors.
  2. External JavaScript file can contain HTML tags.
  3. It would be an error if you place <SCRIPT> tag at both head section as well as inside body section also.

Solutions

  1. False
  2. False
  3. False

 

 
What's Next


The next chapter will acquaint you with the concepts of JavaScript operators and variables. The chapter will further elucidate how to create variables and different types of operators available in JavaScript.

Hop over to the next chapter to get the close-up of JavaScript operators and variables.

         

 
       

 

 
     
Home  |  About Us  |  Privacy Policy  |  Site Map  |  FAQs  |  Contact Us
 
© ExpertRating 2006. All Rights Reserved.