JavaScript
  Home arrow JavaScript arrow Page 4 - Javascript: the Beginning
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Javascript: the Beginning
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2007-10-29

    Table of Contents:
  • Javascript: the Beginning
  • Adding Javascript to an HTML Page
  • Putting JavaScript in its Place
  • Variables

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Javascript: the Beginning - Variables


    (Page 4 of 4 )

    Variables, simply put, are containers that had data. The name variable means that the data inside can change; it varies. Some of the higher level programming languages are picky about what type of data you place in them. Not JavaScript. It, like many nerds, is desperate and will take whatever it can get.

    There are, however, rules for naming a variable. For starters, they are case-sensitive, meaning that you can have a variable named my_variable and a variable named MY_VARIABLE and JavaScript will see it as two different variables. They must also begin with a letter or an underscore.

    This is how you declare or assign a value to a variable:


    <html>

    <head>

    </head>

    <body>

    <script type="text/Javascript">

    var my_variable = "James Payne"

    document.write(my_variable + "<BR>")

    document.write("<i>"+my_variable+"</i>")

    </script>

    </body>

    </html>

    The above code would print out:

      James Payne

      James Payne

    The part var my_variable = "James Payne" names the variable and assigns it the value of James Payne. We then write the value of my_variable to the screen twice, inserting a page break in between and italicizing the second printing.

    You can opt not to use the var in front of the variable name if you wish, though leaving it in makes it easier to identify if you ever need to go back to the code.

    Scope of a Variable

    While we will cover this more in depth later on, variables have two types of life spans. If you declare the variable inside of a function (more on this later), it disappears once the function is completed. If you declare it outside of a function, it disappears when the page is closed (don't worry; if a user revisits the page, the process starts all over again).

    Well that's it for this article. In our next tutorial, we will cover how to insert special characters, working with statements, and if we have time, working with operators. Till then...


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Thanks for dropping by and reading my article. In this tutorial we discuss how to...
     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT