Variables Kevin Harville Variables Variables are a named








- Slides: 8

Variables Kevin Harville

Variables ® Variables are a named space in the computer where a value is stored. ® Examples ® User’s age ® User’s name ® Any characters or numbers you need use in which the values may vary.

Variable Names ® Names are CASE SENSITIVE ® Var total. Students is not Total. Students ® Use letters or underscore. Can use numbers after the first character var Student_Name; ® var Score 7; ® ® Be descriptive. Use no punctuation or spaces. ® var Number. Of. Fish. In. Grandmas. Aquarium;

Variable Scope ® The “scope” of a variable is the range within the program where it can be used. ® If a variable is declared within a function, the scope of the variable is local, meaning limited to that function. ® Other variables are global to the entire script.

Data Types ® Variables in Java. Script are variant. That means that they are usually not specified as being a particular type of data, such as characters, a decimal number, or a number. ® However, we can specify our data as being of a particular type if needed.

Data Types ® Numbers ® Boolean ( true / false ) ® Strings (characters) ® Null values (Java. Script keyword null)

Converting Strings to Numbers ® Any input from the user may be considered by the computer to be strings of characters. ® “ 10” + “ 40” = “ 1040” ® Therefore we tell the computer to consider the text to be integer or floating point (decimal numbers). ® age = parse. Int(age); ® my. Fraction = parse. Float(my. Input);

Just Remember… ® If your input should be an integer convert it using parse. Int(). ® If your input should be a decimal convert it using parse. Float(). ® If your response is Na. N, then the computer can’t convert it to a number
Java Script Strings and Arrays Kevin Harville Strings
Testing and Comparing Values Kevin Harville If Statements
Using Built In Objects Kevin Harville Date instantiation
Java Script Overview By Kevin Harville Java Script
Recognizing Java Script Features Kevin Harville Review this
Loops Kevin Harville for loops for my Var
Using Objects Kevin Harville Objectoriented programming Objectoriented programming
What is a Named Constant A named constant