

Paperback
-
SHIP THIS ITEMIn stock. Ships in 1-2 days.PICK UP IN STORE
Your local store may have stock of this item.
Available within 2 business hours
Related collections and offers
Overview
Product Details
ISBN-13: | 9780072192964 |
---|---|
Publisher: | McGraw-Hill/Osborne Media |
Publication date: | 09/11/2001 |
Series: | Programmer's Reference |
Pages: | 288 |
Product dimensions: | 5.59(w) x 8.53(h) x 0.70(d) |
About the Author
Paul Jobson has been building web sites since 1994 and has extensive experience coding client-side JavaScript, Dynamic HTML, and Perl. He is currently contracting for a Fortune 50 company in the DC Metro area.
Read an Excerpt
Chapter 1: Core JavaScript
This chapter discusses JavaScript's core language conventions, including case sensitivity, keywords, data types, reserved words, and operators to get you rolling if you're new to JavaScript.
Language Conventions
Case Sensitivity
Core JavaScript language is case sensitive. This means keywords, variables, function names, or any other identifiers must contain exactly the same letters in the same case. The variableSomeVariable
is not the same as SOMEVARIABLE
, which is not the same as somevariable
.
Microsoft's Internet Explorer browser is the only deviant from this rule. In Internet Explorer, Core JavaScript is case sensitive, but any objects, and their methods and properties, that are added by the Client-Side JavaScript are not case sensitive. For example, Date ( )
and Math ()
are Core JavaScript functions, and therefore it is invalid to write them as date ()
, DATE ()
, Math ()
, or mAth ()
. On the other hand, the form object is part of Client-Side JavaScript, and therefore it is valid to write it as window. form or window. FORM or window. Form. Remember, these rules apply to Internet Explorer only and it's not good practice to ignore cases.
Code Formatting
Line Breaks and Whitespace
JavaScript ignores line breaks and whitespace, except in strings and tokens. Whitespace represents a space or tab. Tokens are defined as keywords, variable names, numbers, function names, or some place that you wouldn't want a line break or whitespace. A token could be the number 2 002 ; if you added a space, the numbers 200 2 would be considered two tokens.
Semicolons
JavaScript, like many programming languages, has semicolons at the end of statements. Still, JavaScript does not require you to put a semicolon at the end of a statement. Each of the following statements is valid:
ThisMonth = "August" someyear = "2022"; nextnum = 33; testvalue = 300
If there are several statements on one line, you must use semicolons:
thisyear = "2001"; othernum = 100;
Even though semicolons are optional, it is better coding practice not to omit them.
Comments
JavaScript comments are simply notes within the code-and they are not part of the program. Developers (such as you) generally use comments to add notes to the code for later reference. There are two forms of comments in JavaScript. Line comments begin with / / and end with a line break, and multiline comments begin with / * and end with * / . Several lines may fall between these symbols.
// This is a comment num = S; // Comments may follow a line of code. /* Comments may span several lines, as long as you use this kind of commenting */
Literals and Identifiers
A literal represents a value in JavaScript. Literals are fixed values, not variables, which you define. Several types of literals are integer literals, octal literals, hexadecimal literals, and string literals.
Reserved Words
In JavaScript there are several groups of words that fall into the "reserved word" category. Reserved words are words that you should not use as identifiers. You may not use any JavaScript keywords, shown in Table 1-1. JavaScript keywords are pan of the language syntax, so they should be avoided. Also, Java keywords, displayed in Table 1-2, should be avoided. Java keywords are not yet used in JavaScript, but future versions of JavaScript may use them. Table 1-3 lists other identifiers to be avoided-these are names of data types, functions, and variables that are predefined by Client-Side JavaScript. Since Internet Explorer is not case sensitive, all keywords in Table 1-2 should be avoided in lowercase and uppercase. Finally, there are words reserved for possible future extensions to the ECMA-262 standard, which are shown in Table 1-4.
Data Types
Numbers
Numbers are basic data types; numeric literals may be integer or floating point; and integers may be decimal, octal, or hexadecimal. JavaScript does not make a distinction between floating-point and integer values; JavaScript recognizes all numbers as floating-point values. These floating-point numbers may be represented as large as +/- 1.7976931348623157x10308 and as small as +/- 5x10-324.
Integer Literals
Integer literals are represented by Base-10 numbers, which are positive or negative numbers that do not begin with a zero. Integer literals never have decimals, for example...Table of Contents
Acknowledgments | xiii | |
Introduction | xiii | |
1 | Core JavaScript | 1 |
Language Conventions | 1 | |
Case Sensitivity | 1 | |
Code Formatting | 1 | |
Literals and Identifiers | 2 | |
Reserved Words | 2 | |
Data Types | 5 | |
Numbers | 5 | |
Special Numeric Values | 7 | |
Strings | 7 | |
Variables | 9 | |
"Untyped" Variables | 9 | |
Declaring Variables | 9 | |
Operators | 10 | |
JavaScript Operators | 13 | |
Operands | 13 | |
Operator Precedence | 13 | |
Operator Associativity | 14 | |
Types of Operators | 15 | |
2 | Statements and Control Structures | 27 |
Statements | 27 | |
Expression Statements | 27 | |
Compound Statements | 27 | |
var | 28 | |
function | 28 | |
return | 28 | |
with | 28 | |
import and export | 29 | |
The Empty Statement | 29 | |
try ... catch | 30 | |
Control Structures | 30 | |
Conditional | 30 | |
Loops | 33 | |
3 | Functions and Objects | 37 |
Functions | 37 | |
Defining Functions | 37 | |
Executing Functions | 38 | |
Nested Functions | 38 | |
Manipulating Functions as Data | 39 | |
Objects | 43 | |
A Prototype-Based Language | 43 | |
Defining Objects | 44 | |
The Object Superclass | 45 | |
Using Object-Oriented JavaScript | 48 | |
4 | Core Objects and Functions | 51 |
Array | 51 | |
Creating Arrays | 53 | |
Array Methods and Properties | 54 | |
Multidimensional Arrays | 60 | |
Boolean | 61 | |
Creating Boolean Objects and Values | 61 | |
Boolean Methods | 62 | |
Date | 63 | |
The Date Constructor | 67 | |
Date Methods | 68 | |
eval () | 81 | |
Math | 82 | |
Math Methods and Properties | 84 | |
MimeType | 92 | |
MimeType Properties | 94 | |
Number | 94 | |
The Number Constructor | 95 | |
Number Methods and Properties | 95 | |
parseFloat () | 98 | |
parseInt () | 98 | |
RegExp | 99 | |
Defining Regular Expressions | 99 | |
Pattern Matching | 100 | |
RegExp Methods | 108 | |
RegExp Object | 111 | |
String | 113 | |
Creating Strings | 116 | |
String Methods and Properties | 116 | |
5 | JavaScript in the Browser: Client-Side Objects, Methods, and Properties | 129 |
Embedding JavaScript in HTML Pages | 129 | |
[left angle bracket]Script[right angle bracket] Tags | 129 | |
URL | 131 | |
JSS | 132 | |
Entities | 132 | |
The Document Object Model | 133 | |
The navigator Object | 133 | |
navigator.appCodeName | 135 | |
navigator.appMinorVersion | 136 | |
navigator.appName | 136 | |
navigator.appVersion | 136 | |
navigator.cookieEnabled | 136 | |
navigator.cpuClass | 137 | |
navigator.javaEnabled() | 138 | |
navigator.language | 138 | |
navigator.mimeTypes[] | 138 | |
navigator.online | 140 | |
navigator.oscpu | 140 | |
navigator.platform | 140 | |
navigator.plugins | 140 | |
navigator.product | 142 | |
navigator.productSub | 142 | |
navigator.systemLanguage | 143 | |
navigator.userAgent | 143 | |
navigator.userLanguage | 143 | |
navigator.vendor | 143 | |
navigator.vendorSub | 144 | |
The Event Object (Events and Event Handling) | 144 | |
event.altKey, event.ctrlKey, event.shiftKey | 144 | |
event.bubbles | 145 | |
event.button | 145 | |
event.cancelable | 145 | |
event.cancelBubble | 146 | |
event.clientX, event.clientY | 146 | |
event.currentTarget | 146 | |
event.data | 146 | |
event.eventPhase | 146 | |
event.fromElement | 146 | |
event.height | 146 | |
event.keyCode | 147 | |
event.layerX, event.layerY | 147 | |
event.modifiers | 147 | |
event.offsetX, event.offsetY | 147 | |
event.pageX, event.pageY | 147 | |
event.reason | 147 | |
event.returnValue | 148 | |
event.screenX, event.screenY | 148 | |
event.srcElement | 148 | |
event.srcFilter | 148 | |
event.target | 148 | |
event.toElement | 148 | |
event.type | 148 | |
event.TYPE | 149 | |
event.which | 149 | |
event.width | 149 | |
event.x, event.y | 149 | |
The window Object | 150 | |
window._content | 157 | |
window.alert() | 157 | |
window.atob() and window.btoa() | 157 | |
window.back() | 157 | |
window.blur() | 157 | |
window.captureEvents() | 158 | |
window.clearInterval() | 158 | |
window.clearTimeout() | 159 | |
window.close() | 159 | |
window.closed | 159 | |
window.confirm() | 159 | |
window.crypto | 159 | |
window.dialogArguments | 159 | |
window.dialogHeight | 160 | |
window.dialogLeft | 160 | |
window.dialogTop | 160 | |
window.dialogWidth | 160 | |
window.disableExternalCapture() | 160 | |
window.document | 160 | |
window.enableExternalCapture() | 161 | |
window.escape() and window.unescape() | 161 | |
window.event | 161 | |
window.execScript | 161 | |
window.find() | 161 | |
window.focus() | 162 | |
window.forward() | 162 | |
window.frames[] | 162 | |
window.history | 162 | |
window.home() | 162 | |
window.innerHeight | 162 | |
window.innerWidth | 162 | |
window.length | 163 | |
window.location | 163 | |
window.locationbar | 163 | |
window.menubar | 163 | |
window.moveBy() | 163 | |
window.moveTo() | 163 | |
window.name | 163 | |
window.navigate() | 164 | |
window.offscreenBuffering | 164 | |
window.onblur | 164 | |
window.ondragdrop | 164 | |
window.onerror | 164 | |
window.onfocus | 164 | |
window.onload | 164 | |
window.onmove | 165 | |
window.onresize | 165 | |
window.onunload | 165 | |
window.open() | 165 | |
window.opener | 167 | |
window.outerHeight | 167 | |
window.outerWidth | 167 | |
window.parent | 167 | |
window.personalbar | 167 | |
window.print() | 168 | |
window.prompt() | 168 | |
window.releaseEvents() | 168 | |
window.resizeBy() | 168 | |
window.resizeTo() | 168 | |
window.routeEvents() | 169 | |
window.screen | 169 | |
window.screenX | 169 | |
window.screenY | 169 | |
window.scroll() | 169 | |
window.scrollbars | 169 | |
window.scrollBy() | 170 | |
window.scrollTo() | 170 | |
window.self | 170 | |
window.setHotkeys() | 170 | |
window.setInterval() | 170 | |
window.setResizable() | 171 | |
window.setTimeout() | 171 | |
window.setZOptions() | 171 | |
window.showHelp() | 172 | |
window.showModalDialog() and window.showModelessDialog() | 172 | |
window.sidebar | 173 | |
window.status | 174 | |
window.statusbar | 174 | |
window.stop() | 174 | |
window.toolbar | 174 | |
window.top | 174 | |
window.window | 174 | |
window.XOffset | 174 | |
window.YOffset | 175 | |
Document Properties | 175 | |
document.activeElement | 179 | |
document.all | 179 | |
document.alinkColor, document.bgColor, document.fgColor, document.linkColor, document.vlinkColor | 180 | |
document.anchors[] | 181 | |
document.applets[] | 181 | |
document.attributes | 181 | |
document.body | 181 | |
document.characterSet | 182 | |
document.childNodes | 182 | |
document.clear() | 182 | |
document.close() | 183 | |
document.cookie | 183 | |
document.createElement() | 183 | |
document.createStyleSheet() | 183 | |
document.defaultCharset | 183 | |
document.domain | 184 | |
document.elementFromPoint() | 184 | |
document.embeds[] | 184 | |
document.execCommand() | 184 | |
document.expando | 184 | |
document.fileCreatedDate | 187 | |
document.fileModifiedDate | 187 | |
document.fileSize | 188 | |
document.fileUpdatedDate | 188 | |
document.form | 188 | |
document.forms[] | 235 | |
document.frames[] | 235 | |
document.getSelection | 235 | |
document.height | 236 | |
document.images[] | 236 | |
document.lastModified | 236 | |
document.links[] | 236 | |
document.mimeType | 236 | |
document.open() | 236 | |
document.parentWindow | 236 | |
document.queryCommandEnabled() | 237 | |
document.queryCommandIndeterm() | 237 | |
document.queryCommandState() | 237 | |
document.queryCommandSupported() | 237 | |
document.queryCommandText() | 237 | |
document.queryCommandValue() | 238 | |
document.readyState | 238 | |
document.referrer | 238 | |
document.scripts[] | 238 | |
document.selection | 238 | |
document.styleSheets[] | 239 | |
document.title | 239 | |
document.URL | 239 | |
document.width | 239 | |
document.write() | 239 | |
document.writeln() | 239 | |
Appendix | ||
JavaScript Versions Chart | 241 | |
Character Charts | 242 | |
Event Handlers Chart | 251 | |
The Authors' Bookmarks | 253 | |
Web Browsers | 255 | |
Country Codes | 255 | |
JavaScript Security | 258 | |
JavaScript's Inherent Security | 258 | |
Security by Obscurity Doesn't Work | 259 | |
Index | 261 |