-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathident.html
220 lines (195 loc) · 6.73 KB
/
ident.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<html>
<head>
<title>Values, Names, and Literals</title>
</head>
<body>
<h1>JavaScript Values, Names, and Literals</h1>
<ul>
<li><a href="#values">Values</a>
<li><a href="#names">Variable Names</a>
<li><a href="#literals">Literals</a>
</ul>
<hr>
<a name="values"> <h2>Values</h2></a>
<p>
JavaScript recognizes the following types of values:
<ul>
<li>numbers, such as 42 or 3.14159
<li>logical (Boolean) values, either true or false
<li>strings, such as "Howdy!"
<li>null, a special keyword denoting a null value
</ul>
<p>
This relatively small set of types of values, or <i>data types</i>,
enables you to perform useful functions with your applications. Notice that there
is no explicit distinction between integer and real-valued numbers. Nor is there
an explicit date data type in Navigator. However, the date object and related
built-in functions enable you to handle dates.
<p>
Objects and functions are the other fundamental elements in the language.
You can think of objects as named containers for values, and functions as procedures
that your application can perform.
<h3>Datatype Conversion</h3>
<p>
JavaScript is a loosely typed language. That means that you do not have to specify
the datatype of a variable when you declare it, and datatypes are converted
automatically as needed during the course of script execution. So, for example, you could define a variable as follows:
<pre>
var answer = 42
</pre>
<p>
And later, you could assign the same variable a string value, for example:
<pre>
answer = "Thanks for all the fish..."
</pre>
<p>
Because JavaScript is loosely typed, this will not cause an error message.
<p>
In general, in expressions involving numeric and string values, JavaScript converts the numeric values to strings.
For example, consider the following statements:
<pre>
x = "The answer is " + 42
y = 42 + " is the answer."
</pre>
<p>
The first statement will the string "The answer is 42". The second statement will return the string "42 is the answer".
<p>
JavaScript provides several special functions for manipulating string and numeric values:
<ul>
<li><a href="builtin.html#eval">eval</a>attempts to evaluate a string representing any JavaScript literals or variables,
converting it to a number.
<li><a href="builtin.html#parseInt">parseInt</a> converts a string to an integer of the specified radix (base), if possible.
<li><a href="builtin.html#parseInt">parseFloat</a> converts a string to a floating-point number, if possible.
</ul>
<hr>
<a name="names"> <h2>Variables</h2></a>
<p>
You use variables to hold values in your application. You
give these variables <i>names</i> by which you reference them,
and there are certain rules to which the names must conform.
<p>
A JavaScript identifier or <i>name</i> must start with a letter or
underscore ("_"); subsequent characters can also be
digits (0-9). Letters include the characters "A" through
"Z" (uppercase) and the characters "a" through
"z" (lowercase).
JavaScript is case-sensitive.
<p>
Some examples of legal names are:
<ul>
<li><code>Number_hits</code>
<li><code>temp99</code>
<li><code>_name</code>
</ul>
<h3>Variable scope</h3>
<p>
The <i>scope</i> of a variable is where you can use it in a script.
In JavaScript, there are two scopes that a variable can have:
<ul>
<li>global: you can use the variable anywhere in the application.
<li>local: you can use the variable within the current function.
</ul>
<p>
To declare a local variable inside a function, use the <b>var</b> keyword,
for example:
<pre>
var total = 0
</pre>
<p>
To declare a global variable, declare the variable by assignment, that is
simply assign the desired value to the variable (either in a function or
outside a function), for example:
<pre>
total = 0
</pre>
<p>
It is good programming practice to
declare global variables at the beginning of your script, so
that functions will inherit the variable and its value.
<hr>
<a name="literals"> <h2>Literals</h2></a>
<p>
Literals are the way you represent values in JavaScript.
These are fixed values that you <i>literally</i> provide in your
application source, and are not variables. Examples of literals
include:
<ul>
<li><code>42</code>
<li><code>3.14159</code>
<li><code>"To be or not to be"</code>
</ul>
<h3>Integers</h3>
<p>
Integers can be expressed in decimal (base 10), hexadecimal (base
16), or octal (base 8) format. A decimal integer literal consists
of a sequence of digits (optionally suffixed as described below)
without a leading 0 (zero).
<p>
An integer can be expressed in octal or hexadecimal rather than
decimal. A leading 0 (zero) on an integer literal means it is
in octal; a leading 0x (or 0X) means hexadecimal. Hexadecimal
integers can include digits (0-9) and the letters a-f and A-F.
Octal integers can include only the digits 0-7.
<h3>Floating Point Literals</h3>
<p>
A floating point literal can have the following parts: a decimal
integer, a decimal point ("."), a fraction (another
decimal number), an exponent, and a type suffix. The exponent
part is an "e" or "E" followed by an integer, which can be signed (preceded by
a "+" or "-").
A floating point literal must have at least one digit, plus either
a decimal point or "e" (or "E"). Some examples of floating point literals
are:
<ul>
<li>3.1415
<li>-3.1E12
<li>.1e12
<li>2E-12
</ul>
<h3>Boolean Literals</h3>
<p>
The boolean type has two literal values: <b>true</b> and <b>false</b>.
<h3>String Literals</h3>
<p>
A string literal is zero or more characters enclosed in double
(") or single (') quotes. A string must be delimited by quotes
of the same type; that is, either both single quotes or double
quotes. The following are examples of string literals:
<ul>
<li><code>"blah"</code>
<li><code>'blah'</code>
<li><code>"1234"</code>
<li><code>"one line \n another line"</code>
</ul>
<h4>Special Characters</h4>
<p>
You can use the following special characters in JavaScript string literals:
<ul>
<li><b>\b</b> indicates a backspace.
<li><b>\f</b> indicates a a form feed.
<li><b>\n</b> indicates a new line character.
<li><b>\r</b> indicates a carriage return.
<li><b>\t</b> indicates a tab character.
</ul>
<h4>Escaping Characters</h4>
<p>
You can insert quotes inside of strings by preceding them by a backslash.
This is known as <i>escaping</i> the quotes.
For example,
<pre>
var quote = "He read \"The Cremation of Sam McGee\" by R.W. Service"
document.write(quote)
</pre>
<p>
The result of this would be<p>
<script>
var quote = "He read \"The Cremation of Sam McGee\" by R.W. Service"
document.write(quote)
</script>
</body> </html>
<!--
FILE ARCHIVED ON 23:25:17 Jun 17, 1997 AND RETRIEVED FROM THE
INTERNET ARCHIVE ON 18:07:49 Nov 08, 2018.
ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
SECTION 108(a)(3)).
-->