Javascript Operator corrections and Brief Description of Cookies
Cookies and Functions
In my research I could
find no other reasonable way to remember information on a session to
session basis without using cookies.
You can pass information from one
frame to another without cookies, but once you have them mastered you
can also use them for frame to frame information sharing.
For those of you who haven't read the section in the book about cookies,
a cookie is a small file which is associated with a URL. Each URL only stores
one cookie ( but can contain multiple pieces of information along with
multiple expiration dates for each piece of info.
Cookies can be very easy to use by implementing functions to read
a cookie (if it exists), and store/update a cookie. We used
SetCookie(name, value); and GetCookie(name); (returns value). Full
details are forthcoming.
Cookie use by this website
In our implementation we used two cookies, the first called 'id' has
an expiration of 7 days and the value of id is your name. the second,
called "checked" has an expiration time of 10 minutes and if present
(not expired) indicates you have entered your id in the last 10
minutes. Ideally we should update this expiration time as you do
things, but we didn't include that.
Name/Id Checking
We have included some code to check that you really entered a
name (we expect a name to have 5 or more characters, we know this of
course is not always true, but it is a good example of how web
programmers screw up. (I hate it when I can't enter my phone number
as aaa-xxx-yyyyy or (aaa)xxx-yyyy when some websites want aaaxxxyyyy
AND don't even make it clear.
Links "visited" a mystery unraveled!
In reviewing cookies we found the answer to a question which has
perplexed us since even before this course. Specifically, Looking at
the '<A>' tag, there is normally a different color for targets
that have been visited vs those that have not been visited.
Obviously this info must be stored somewhere outside the HTML
file. It doesn't appear to be a cookie, as I cleared cookies and I
still see different colors. The answer (I found out today) is the IE
'Internet Temporary Files Folder' (if you are using Internet
Explorer, recent versions) has cookies and the full copy of pages you
have visited recently.
If you want to clear the links "visited"
indicator it can be done by deleting the appropriate file in the
mentioned directory or by updating the date modified field on the web
copy of the file. If you clear cookies alone, it does not delete the
files that indicate "visited".
Logical Operators - an explanation
Correction to book
On page h.03 of our book they define ! as a logical NOT, then define
| as a negaton (true if expression was false and false if expression was true).
This second description also defines a logical NOT.
Another reference
http://www.devguru.com/Technologies/ecmascript/quickref/bitwise_operators.html
describes | as a bitwise OR operator. This is consistent with C and makes more sense.
Is the book wrong?
In our research we could not find a negaton in reference to computer programming,
or any logical operation.
Even google doesn't find a related definition.
Some examples of logical operators
The arithmetic bitwise OR: | =arithmetic result
| is a bitwise arithmetic operator
(an OR) in Javascript or C++ or many other languages, it requires two operands
that is (A|B) is a valid expression which will yield (in javascript) an arithmetic,
not logical result,
The logical NOT: ! =logical result
Conversely, the expression (|A), or (|false) is not a valid JavaScript
expression.
An other arithmetic OR
Again, you can not use the expression |false, it is illegal in javascript
(the whole statement is ignored), !false is ok and returns a true.
In addition to my empirical findings, I was attracted
to the so called "negaton" because it makes no sense either from a Boolean
logic point of view nor from a computer logic point of view.
Summary:
There is no such thing as a negaton
An arithmetic logical operator operates on two numeric values
logically (on a bit bit basis, there is no carry) and produces a numeric
result
Conversely, a logical operator operates on a logical value
(true or false, sometimes represented as 1 or 0). In most
languages and computer systems any non-zero value is treated as
true, but Javascript has special conditions.
the ^ (XOR or Exclusive OR) on page h.03 listed as a logical
operator is an arithmetic logical operator with two operands
(0^1=1, 0^0=0, 1^0=1, 1^1=0
The | (OR) shown on page h.03 as a negaton is actually an
arithmetic logical OR
The & (AND) operator shown on page H.02 performs a bit by bit
AND on all
bits of the operands. (this expands, but does not contradict
the book)