Cover | Table of Contents | Colophon
Rewind to early 1995. Netscape had just hired Brendan Eich away from MicroUnity Systems Engineering, to take charge of the design and implementation of a new language. Tasked with making Navigator’s newly added Java support more accessible to non-Java programmers, Eich eventually decided that a loosely typed scripting language suited the environment and audience, namely the few thousand web designers and developers who needed to be able to tie into page elements (such as forms, or frames, or images) without a bytecode compiler or knowledge of object-oriented software design.The language he created was christened “LiveScript,” to reflect its dynamic nature, but was quickly (before the end of the Navigator 2.0 beta cycle) renamed JavaScript, a mistake driven by marketing that would plague web designers for years to come, as they confused the two incessantly on mailing lists and on Usenet. Netscape and Sun jointly announced the new language on December 4, 1995, calling it a “complement” to both HTML and Java.(From “JavaScript: How Did We Get Here?” O’Reilly Network, April 2001.)
Date or String; it will remain a Date or a String whether implemented in Safari or
Navigator. An instance of an object from the DOM would be the document object, which represents that portion
of the browser that holds the web page. How these DOM objects are
exposed and manipulated within the browser’s respective implementation
of JavaScript (or ECMAScript) is what leads to cross-browser
incompatibility.style attribute.type attribute, and add whatever JavaScript
you want:<script type="text/javascript"> ...some JavaScript </script>
head element in the document (delimited by
opening and closing head tags), but
they can also be included in the body
element—or even in both sections.alert
function to open a message box containing the “Hello, World!”
text.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Example 1-1</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript"> var dt = Date( ); // say hello to the world var msg = 'Hello, World! Today is ' + dt; alert(msg); </script> </head> <body> </body> </html>
http://www.cert.org/advisories/CA-2000-02.html.
The CGISecurity.com site has an in-depth FAQ on XSS and can be found
at http://www.webaim.org) has a wonderful
tutorial on creating accessible JavaScript (available at http://www.webaim.org/techniques/javascript/).
It covers the ways you shouldn’t use JavaScript, such as using JS for
menus and other navigation. However, the site also provides ways you
can use JS to make a site more accessible.string,
boolean, and number. Along the way, we’ll explore escape
sequences in strings and take a brief look at Unicode. The chapter also
delves into the topic of variables, including variable scope and what
makes valid and meaningful variable identifiers. We’ll also look at the
influences on identifiers that originate from the newest generation of
JavaScript applications based on Ajax._variableidentifier variableIdentifier $variable_identifier var_ident
_variableidentifier variableIdentifier $variable_identifier var_ident
_üvalid T\u0009
strngVariable strngvariable
break | else | new | var |
case | finally | return | void |
catch | for | switch | while |
continue | function | this | with |
default | if | throw | |
delete | in | try | |
do | instanceof | typeof |
abstract | enum | int | short |
boolean | export | interface | static |
byte | extends | long | super |
char | final | native | synchronized |
class | float | package | throws |
const | goto | private | transient |
debugger | implements | protected | volatile |
double | import | public |
num_value = 3.5;
var num_value = 3.5;
var keyword.var keyword is strongly recommended;
doing so with local variables helps prevent collision between local and
global variables of the same name. If a variable is explicitly defined
in a function, its scope is restricted to the function, and any
reference to that variable within the function is understood by both
developer and JavaScript engine to be that local variable. With the
growing popularity of larger, more complex JS libraries, using var prevents the unexpected side effects
created by using what you think is a local variable, only to find out
it’s global in scope.message.
The page includes two external JavaScript files, both of which also set
the same variable: one, globally, outside the function that uses it; the
other, locally, within the function. None of the examples use the
string, numeric, and boolean. Each is specifically differentiated
by the literal it contains: string, numeric, and boolean. However, there
are also built-in objects known as number, string, and boolean. These would seem to be the same
thing, but aren’t: the first three are classifications of primitive
values, while the latter three are complex constructions with a type of
their own: object.string variable was
demonstrated in Example 2-1. Since
JavaScript is a loosely typed language, there isn’t anything to
differentiate it from a variable that’s a number or a boolean, other
than the literal value assigned it when it’s initialized and the
context of the use."This is a string" 'But this is also a string'
"This is 1 string." "This is--another string."
\\n for
end-of-line terminator.const is used to create a JavaScript const:const CURRENT_MONTH = 3.5;
$someVariable _someVariable 1Variable some_variable somèvariable function .someVariable some*variable
var some_month; function theMonth // function to return current month current-month // a constant var summer_month; // an array of summer months MyLibrary-afunction // a function from a JavaScript package
var someString = ‘Who once said, “Only two things are infinite, the universe and human stupidity, and I’m not sure about the former.”’
someMonth, is passed to the function. How
would you determine whether it’s null or undefined?var bValue = true var sValue = "this is also true"
var bValue = true; var sValue = "this is also true";
var firstName = 'Shelley' ; var firstName = 'Shelley';
var bValue = true var sValue = "this is also true"
var bValue = true; var sValue = "this is also true";
var firstName = 'Shelley' ; var firstName = 'Shelley';
var firstName = 'Shelley'; alert(firstName);
for loops, which have a beginning and
end. Others, though, stand all on their own: one statement, one line.
Among these simple statements are those for assignment.nValue = 35.00;
nValue = nValue + 35.00;
nValue = someFunction( );
Following the assignment statement, the second most common type of statement is the arithmetic expression that involves the arithmetic operators, discussed next.
nValue = vValue + 35.00;
nValue = nValue + 30.00 / 2 - nValue2 * 3;
var bigCalc = varA * 6.0 + 3.45 - varB / .05;
Return to Learning JavaScript