Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

JavaScript Variables

By Exforsys | on April 15, 2007 |
JavaScript Tutorial

JavaScript Variables

In this JavaScript tutorial, you will learn about JavaScript variables, rules for variable names in JavaScript, declaration of variable in JavaScript, variables usage, JavaScript in external file, how to place the JavaScript in external file and how to execute this JavaScript placed in external file.

Just like any programming language, variables in JavaScript are also used to store values. The value of the variable can be edited as required by the programmer.

Rules for Variable Names in JavaScript:

Some of the rules for forming variable names are as follows:

  • Variable names are case sensitive.
  • They must begin with a letter or the underscore character

Now let us see how to declare a variable name.

Declaration of Variable in JavaScript:

This is done by using the var statement. The syntax of var statement is

var variable name = value

In any programming language, a variable must first be declared. Storage location must be allocated for the variable before using the variable.

In JavaScript, it is possible to skip the command var and directly assign value to variable names. For Example:

variable name = value

Using the variable name Exforsys and the notion that a programmer wants to assign the value “Training” to this variable it can be written two ways:

var Exforsys = “Training”

or It can also be done as follows:

Exforsys = “Training”

Variables Usage:

The variables can be declared and used in two ways namely:

  • Locally
  • Globally

When a programmer declares a JavaScript variable within a function, the variable can only be accessed within that function. When the control moves out of the function, the variable is destroyed. These variables are called local variables. Each of the local variables placed with the same name in different functions are different because they are recognized only within the function in which they are declared.

If a programmer declares a JavaScript variable outside a function, all the functions on the page can access the variable. The lifetime of these variables starts when they are declared, and ends when the page is closed.

JavaScript in External File:

There may be scenarios in which the same functionality of script needs to be executed in several places in the program. Instead of writing the same JavaScript in several places (which would cause poor optimization of code) the programmer can place the JavaScript in an external file thereby allowing programmers to make use of single external file at more the one place.

How to place the JavaScript in External file:

This process is very simple. The code or the JavaScript that needs to be executed in several places in the program is written separately in a file and then saved with extension as .js for that file.

How to execute this JavaScript placed in External File:

This is performed using the attribute src for the <script> tag.

The script tag is placed as needed in either the HEAD section or the BODY section using the src attribute as follows:

<html>
<head>
<script src="filename.js"></script>
</head>
<body>
</body>
</html>

Suppose the JavaScript is placed in an external file named Exforsys.js then it is executed by placing it as:

<html>
<head>
<script src="Exforsys.js"></script>
</head>
<body>
</body>
</html>

« « Ways to Improve Self Confidence
Ways to keep conversation going » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 394 Followers
  • Popular
  • Recent
  • JavaScript Alert Box

    April 25, 2007 - 0 Comment
  • JavaScript History Object Properties and Methods

    August 5, 2007 - 0 Comment
  • JavaScript Two Dimensional Arrays

    June 7, 2007 - 0 Comment
  • JavaScript Event Object Properties and Methods

    June 9, 2007 - 0 Comment
  • JavaScript Introduction

    April 5, 2007 - 0 Comment
  • JavaScript Confirm Box

    April 25, 2007 - 0 Comment
  • JavaScript Location Object Properties

    June 13, 2007 - 0 Comment
  • JavaScript Array Operations

    July 29, 2007 - 0 Comment
  • JavaScript FileUpload Object

    May 18, 2007 - 0 Comment
  • JavaScript Features

    April 24, 2007 - 0 Comment
  • JavaScript Objects

    August 12, 2007 - 0 Comment
  • JavaScript String Object

    August 12, 2007 - 0 Comment
  • JavaScript Date Object

    August 12, 2007 - 0 Comment
  • JavaScript Math Object

    August 9, 2007 - 0 Comment
  • JavaScript Windows Object Properties Part II

    August 9, 2007 - 0 Comment
  • JavaScript Windows Object Properties Part I

    August 8, 2007 - 0 Comment
  • JavaScript Window Object Timeout Methods

    August 8, 2007 - 0 Comment
  • JavaScript Document Object Methods Part II

    August 7, 2007 - 0 Comment
  • JavaScript Document Object Methods Part I

    August 5, 2007 - 0 Comment
  • JavaScript History Object Properties and Methods

    August 5, 2007 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • JavaScript Objects
  • JavaScript String Object
  • JavaScript Date Object
  • JavaScript Math Object
  • JavaScript Windows Object Properties Part II

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT