JavaScript

Tuesday April 8, 2025
updated: April 10, 2002

 
Home
Getting Started
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Resources
Credits

 

 


Lesson 3: Variables

A 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.

Value

A value in JavaScript is a piece of information that can be a string, number, Boolean, Null, Object, or a Function as defined in the following table

Value Types

Type
Description
Example
string a series of characters inside quote marks "JavaScript is cool"
number any numeric value (not inside quotes) 4.55
Boolean either true or false true
Null Empty, devoid of any value null
Object properties and methods of an object see lesson 5
Function value returned by a function see lesson 6

Naming Variables

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

Declaring a Variable

You can create a variable with or without the var statement:

var strname = some value
strname = some value
var= some value
var= a number

Assigning a Value to a Variable

You can assign the variable "strname" the value of "groovy" by:

var strname = "groovy"
strname = "groovy"
var= "groovy"
var=23.7

back button
next button

© 2002 Tracy Johnson