Javascript Knowledge

  • what is javascript

  • javascript Variable
  • javascript function
  • javascript Event

  • JavaScript If
  • javascript for

  • javascript object
  • Javascript String
  • Javascript Date
  • Javacsript Array
  • Javascript Math

  • Javascript onclick
  • JavaScript onload

  • Javascript Frame
  • Javascript Image
  • Javascript Style
  • Javascript Textarea
  • Javascript Table
  • Javascript window
  • Javascript Location
  • Javacsript form
  • Javascript Checkbox
  • Javascript Input
  • Javascript Radio
  • Javascript Select
  • Javascript Submit

  • Javascript alert
  • Javascript close
  • Javascript confirm
  • Javascript Document open
  • Javascript getElementById
  • Javascript print
  • Javascript reload
  • Javascript remove
  • JavaScript replace
  • Javascript setTimeout
  • JavaScript split
  • JavaScript substring
  • Javascript window open
  • window showmodaldialog

  • Javascript href
  • Javascript IFrame
  • Javascript innerHTML
  • Javascript selectedindex
  • Javascript URL
  • Javascript window Location

  • javascript write to file
  • JavaScript write
  • javascript string to integer
  • Javascript popup
  • Javascript return
  • Javascript Obfuscator
  • Javascript disable
  • Javascript Hide
  • More others

    Javascript
    CSS
    PHP

     

    Javascript Variable


    Variables in Javascript behave the same as variables in most popular programming languages (C, C++, etc) except that you don't have to declare variables before you use them.

    Javascript Using Variables

    A variable's purpose is to store information so that it can be used later. A variable is a symbolic name that represents some data that you set. To think of a variable name in real world terms, picture that the name is a grocery bag and the data it represents are the groceries. The name wraps up the data so you can move it around a lot easier, but the name is not the data!

    A Javascript variable is a "container" for information you want to store. A variable's value can change during the script. You can refer to a variable by name to see its value or to change its value.

    Rules for variable names:

    Variable names are case sensitive

    They must begin with a letter or the underscore character

    JavaScript is case-sensitive! A variable named strname is not the same as a variable named STRNAME!

    Lifetime of Variables

    When you declare a variable within a function, the variable can only be accessed within that function. When you exit the function, the variable is destroyed. These variables are called local variables. You can have local variables with the same name in different functions, because each is recognized only by the function in which it is declared.

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

    A Variable Example

    When using a variable for the first time it is not necessary to use "var" before the variable name, but it is a good programming practice to make it crystal clear when a variable is being used for the first time in the program. Here we are showing how the same variable can take on different values throughout a script.

    HTML & Javascript Code:

    <body>

    <script type="text/javascript">

    <!--

    var linebreak = "<br />"

    var my_var = "Hello World!"

    document.write(my_var)

    document.write(linebreak)

    my_var = "I am learning javascript!"

    document.write(my_var)

    document.write(linebreak)

    my_var = "Script is Finishing up..."

    document.write(my_var)

    //-->

    </script>

    </body>

    Display:

    Hello World!

    I am learning javascript!

    Script is Finishing up...

    We made two variables in this example. One to hold the HTML for a line break and the other was a dynamic variable that had a total of three different values throughout the script.

    To assign a value to a variable you use the equal sign (=) with the variable on the left and the value to be assigned on the right. If you swap the order then your script will not work correctly! In english the Javascript "myVar = 'Hello World!'" would be: myVar equals 'Hello World!'.

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     





















     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

  • Javascript |