Java Reference
In-Depth Information
The least obvious of these is the last, which represents individual characters by their character
number in the Latin‐1 character set rather than by their normal appearance. Let's pick an example:
Say you wanted to include the copyright symbol (©) in your string. What would your string need to
look like? The answer is "\xA9 Paul Wilton" .
Similarly, you can refer to characters using their Unicode escape sequence. These are written
\u NNNN , where NNNN refers to the Unicode number for that particular character. For example,
to refer to the copyright symbol using this method, you use the string \u00A9 .
Boolean data
The use of yes or no, positive or negative, and true or false is commonplace in the physical world.
The idea of true and false is also fundamental to digital computers; they don't understand maybes,
only true and false. In fact, the concept of “yes or no” is so useful it has its own data type in
JavaScript: the boolean data type. The boolean type has two possible values: true for yes and false
for no.
The purpose of boolean data in JavaScript is just the same as in the world outside programming: it
enables you to answer questions and make decisions based on the answer. For example, if you are
asked, “Is this topic about JavaScript?” you would hopefully answer, “Yes it is,” or you might also
say, “That's true.” Similarly, you might say, “If it's false that the subject of the topic is JavaScript,
then put it down.” Here you have a boolean logic statement (named after its inventor George Boole),
which asks a question and then does something based on whether the answer is true or false. In
JavaScript, you can use the same sort of boolean logic to give your programs decision‐making
abilities. You take a more detailed look at boolean logic in the next chapter.
variaBles—storing data in memorY
Data can be stored either permanently or temporarily.
You will want to keep important data, such as the details of a person's bank account, in a
permanent store. For example, when Ms. Bloggs takes ten dollars or pounds or euros out of her
account, you want to deduct the money from her account and keep a permanent record of the new
balance. Information like this might be stored in something called a database .
However, in other cases you don't want to permanently store data, but simply want to keep a
temporary note of it. Let's look at an example. Say Ms. Bloggs has a loan from BigBank Inc.,
and she wants to find out how much is still outstanding on this loan. She goes to the online
banking page for loans and clicks a link to find out how much she owes. This is data that will be
stored permanently somewhere. However, suppose you also provide a facility for increasing loan
repayments to pay off the loan early. If Ms. Bloggs enters an increased repayment amount into
the text box on the web page, you might want to show how much sooner the loan will be paid.
This will involve a few possibly complex calculations, so to make it easier, you want to write code
that calculates the result in several stages, storing the result at each stage as you go along, before
providing a final result. After you've done the calculation and displayed the results, there's no
need to permanently store the results for each stage, so rather than use a database, you need to use
 
Search WWH ::




Custom Search