Note 3 for Web Scripting
Watch & Read:
Data Type: Numerical (123..), text (string) and boolean (True - False)
A variable is a placeholder or container for use within the program. You should but you don't have to declare your variables.
var myvariable
Syntax for Variables
- Variable names are case sensitive
- They must begin with a letter or the underscore
- The variable must not use a reserved word
- abstract
- as
- boolean
- break
- byte
- case
- catch
- char
- class
- continue
- const
- debugger
- default
- delete
- do
- double
- else
- enum
- export
- extends
- false
- final
- finally
- float
- for
- function
- goto
- if
- implements
- import
- in
- instanceof
- int
- interface
- is
- long
- namespace
- native
- new
- null
- package
- private
- protected
- public
- return
- short
- static
- super
- switch
- synchronized
- this
- throw
- throws
- transient
- true
- try
- typeof
- use
- var
- void
- volatile
- while
- with
Global vs Local variables: When you declare a variable within a function, the variable can only be accessed within that function.
Arithmetic Operators
Operator Description Example Result + Addition x=4
y=2
x+y6 - Subtraction x=5
y=3
x-y2 * Multiplication x=5
y=6
x*y30 / Division 20/5
5/24
2.5% Modulus (division remainder) 5%2
10%8
10%21
2
0++ Increment x=8
x++x=9 -- Decrement x=9
x--x=8 Assignment Operators
Operator Example Is The Same As = x=y x=y += x+=y x=x+y -= x-=y x=x-y *= x*=y x=x*y /= x/=y x=x/y %= x%=y x=x%y Comparison Operators
Operator Description Example == is equal to 6==7 returns false === is equal to
The difference is it checks both value and type!
x=5
y="5"x==y returns true
x===y returns false!= is not equal 9!=8 returns true > is greater than 2>7 returns false < is less than 7<9 returns true >= is greater than or equal to 6>=7 returns false <= is less than or equal to 1<=6 returns true
VIP:
+ is used for concatination and for addition. You have to pay attention to how the data is classified (number or string). If you need to make sure a variable is a number, use Number() methnod.
Example: X =A + B can be written as X=Number(A) + Number(B)
Terms you need to Lookup:
Variable, Array, Data types, string, boolean, global, local, reserved words
Review the following:
Variable
Homework:
Reminder: Post on the Discussion Board Section at least one URL of a Web Page that uses a Web script and describe how the script works.
You should Read Chapter 2
Final Step:
Imagine that your mind is a DVD recorder / player and you can review this content anytime you want. I want you to close your eyes and quickly review in your mind everything we covered in class.
I also want you to review everything we covered before you go to bed because I want your mind to process this information while you sleep. You don’t need to spend much time on this review, 5 minutes will be enough!