Kids

Can

JavaScript

Variables

Variables are containers used to store values.
They are declared (made) with the keyword var : var myVar; The name myVar points now at the empty container .
A value is assigned to the variable with the operator = , var myVar = "Hinemoa";.The value is now stored in the container.
The name of the variable has to be a unique identifier so we can find the right container and retrieve the value.
The rules for variable names are:

  • start with: a letter, _ or $.
  • can contain: letters, _ or $ and numbers.
  • case sensitive: myVar is not the same name as myvar.
Correct Examples $total _sum, firstName, x, printjob3
Wrong Examples 6job, &total, my-name, phone@work

Variable names can be used in operations : x=3 y=7 z = x + y
Existing Variables can change data types: var X=new specialObj('John',21) ; X = 'hello'. X now contains the String 'hello'. The container with the specialObj() still exist, but can't be retrieved and will be collected by the garbage collector.

  • declare assigncreate unique identifier that points at the variable container and store value
  • variable nameshave to be unique and comply with rules
  • operationsvariables names can be used in operations


  • <-----Back        Next --->

    This username already exists.

    This username already exists.

    Login or register to save your work.

    User name field is empty.

    Your username needs to be at least 7 characters long.

    Your username can not contain any of the following characters: ",', <, > , < and whitespaces.

    Please enter a correct email addresss .

    This email address is not found in our database .

    Your password needs to be at least 7 characters long.

    login
    username
    password
    forgot password
    email
    register
    username
    password
    email