Where can a web script run?
Client side (in the web browser used to view the pages) or server side (on the server that hosts the website).
What is client-side scripting?
Scripts executed on local computers after you have loaded the web pages.
Which languages can the browser understand?
JavaScript, HTML (the structure of the page) and CSS — not PHP.
What is JavaScript used for?
It is a scripting language used to enhance the functionality and appearance of web pages.
What is the BOM? Name its important objects.
The Browser Object Model, used to interact with the browser. Important objects: document, location, history, navigator, screen, frames.
What is the DOM, and how does it organize a page?
The Document Object Model deals with the document's HTML elements, organizing them in a tree structure (DOM tree) in which every element is an object (a node) with properties and methods; the browser builds it when the page loads.
In an HTML document's DOM tree, what is the root element, and what are its two children?
The root element is <HTML>, under Document; its children are <HEAD> and <BODY>.
What processes JavaScript commands, and why are scripts often put in the head?
JavaScript interpreters in the browsers. The browser interprets the contents of the head section first.
What does the <script> tag do, and what does its type attribute specify?
It indicates that the text which follows is part of a script. type specifies the MIME type / scripting language, e.g. text/javascript (it may be omitted in HTML5).
What is a string literal?
A string of characters contained between double quotation (") marks.
What is an object?
Something residing in the computer's memory that contains information used by the script; it has attributes (data) and behaviors (methods), and its methods use the data to perform actions.
Is the semicolon required in JavaScript? Is JavaScript case sensitive?
Every statement should end with a semicolon (statement terminator), although none is required by JavaScript. Yes, it is case sensitive — wrong case is a syntax error.
writeln vs. write
writeln writes a line of HTML5 text in the document. write displays a string like writeln but does not position the output cursor at the beginning of the next line after writing.
Why place JavaScript code in a separate file?
It makes the code more reusable, because it can be included into any HTML5 document.
What is the + operator called when it joins two strings?
The concatenation operator.
Which object and method display an alert dialog?
The browser's window object, method alert; its argument is the string to display.
What is an escape sequence? Give \n and \t.
A backslash combined with the next character in a string. \n = newline (cursor to the beginning of the next line); \t = horizontal tab.
How do you put a double quote inside a double-quoted string, and a backslash?
\" for a double quote and \\ for a backslash (Fig. 6.4).
Dynamic vs. static web pages
Dynamic pages' content can change: scripting generates part or all of the page's content at the time it is shown.
What does prompt do, and what are its two arguments?
Displays a dialog into which the user can type a value. First argument: the message (prompt). Optional second argument: the default string in the text field.
What is a variable, and how is it declared?
A location in the computer's memory where a value can be stored for use by a script; it has a name, type and value and should be declared with the keyword var.
Rules for a valid JavaScript identifier
Letters, digits, underscores (_) and dollar signs ($); it must not begin with a digit and must not be a reserved keyword.
What does null mean, and what does writing it display?
It signifies that a variable has no value (it is not a string literal). Writing a null value to the document displays the word "null".
What does parseInt do?
Converts its string argument to an integer.
What does the % operator do?
It is the remainder operator: it yields the remainder after division.
Arithmetic precedence in JavaScript
*, / and % are applied first (left to right if several); + and - are applied next (left to right).
What does an if statement do?
Lets a script make a decision based on the truth or falsity of a condition: the body executes only if the condition is true.
Equality vs. relational operators: which have higher precedence?
Relational operators (>, <, >=, <=) have higher precedence than the equality operators (==, !=); equality operators associate left to right.
How do you get the current local time in JavaScript?
Create a Date object with the new operator: new Date().