01.04.JS Variables
01.04.JS Variables
Variables
INTERACTIVITY
01.04 Variables WITH JAVASCRIPT
Storing Data
• Part of learning to program is learning to store
data
• In JavaScript, data is stored in variables
• To use a variable, you have to declare it
var name;
keyword variable name
INTERACTIVITY
01.04 Variables WITH JAVASCRIPT
Storing Data
Variable Names
• Consists of letters, digits, underscores, and
dollar sign($)
• Can not start with a digit
• Are case-sensitive…
• name Name, naMe, NAME are all different variables
Variable assignments
• It is silly to have a variable if you are
never going to use it
• You can assign values using the =
operator
var name =“Colleen” ;
assignment operator
INTERACTIVITY
01.04 Variables WITH JAVASCRIPT
Assignment statements
• I like to refer to the LHS and RHS of statements
• LHS – the variable being updated
• RHS – the new value that will be stored in the
variable
var name;NO!!
“Colleen” = name;;
name =“Colleen”
LHS RHS
INTERACTIVITY
01.04 Variables WITH JAVASCRIPT
Using a Variable
Review
• Variables are a key component of creating
interactive programs
• We will be using them in the remaining
lectures so practice them and feel
comfortable
INTERACTIVITY
01.04 Variables WITH JAVASCRIPT
Acknowledgements/Contributions
These slides are Copyright 2015- Colleen van Lent as part of
http://www.intro-webdesign.com/ and made available under a Creative
Commons Attribution Non-Commercial 4.0 License. Please maintain
this last slide in all copies of the document to comply with the attribution
requirements of the license. If you make a change, feel free to add
your name and organization to the list of contributors on this page as
you republish the materials.