0% found this document useful (0 votes)
23 views

01.04.JS Variables

The document discusses variables in JavaScript and how they are used to store and assign data. Variables are declared with the var keyword and can be assigned values. Variable names follow certain naming conventions and variables can be used to store user input from prompts and other values like dates. Variables are a key part of building interactive programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

01.04.JS Variables

The document discusses variables in JavaScript and how they are used to store and assign data. Variables are declared with the var keyword and can be assigned values. Variable names follow certain naming conventions and variables can be used to store user input from prompts and other values like dates. Variables are a key part of building interactive programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

INTERACTIVITY

01.04 Variables WITH JAVASCRIPT

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 Name Memory Location Value “stored” in computer


name 11001100001101 “Christopher”
age 11001100001110
… 11001100001111
… 11001100010000
… 11001100010001
… 11001100010010
… 11001100010011
INTERACTIVITY
01.04 Variables WITH JAVASCRIPT

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

• Should be mnemonic (meaningful)


INTERACTIVITY
01.04 Variables WITH JAVASCRIPT

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

var name = prompt(“What is your name?”);


document.write(name);
var date= Date();
document.write(date);
var location= window.location;
document.write(location);
INTERACTIVITY
01.04 Variables WITH JAVASCRIPT

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.

Initial Development: Colleen van Lent , University of Michigan School of


Information

You might also like