02.06.2013 Views

JavaScript & jQuery: The Missing Manual ... - Robert Guajardo

JavaScript & jQuery: The Missing Manual ... - Robert Guajardo

JavaScript & jQuery: The Missing Manual ... - Robert Guajardo

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Top <strong>JavaScript</strong><br />

Programming<br />

Mistakes<br />

<strong>The</strong>n finish the object:<br />

var options = {<br />

rules : {<br />

name : 'required',<br />

email: 'email'<br />

},<br />

messages : {<br />

name : 'Please type your name',<br />

email: 'Please type your e-mail address.'<br />

}<br />

};<br />

This approach lets you check your work through various steps and makes it a lot<br />

easier to identify any mistakes in punctuation.<br />

Table 15-1. Firefox’s Error Console (discussed on page 35) provides the clearest description of syntax<br />

error messages. When a script isn’t working, preview it in Firefox and review the Error Console. Here are<br />

a few of the most common error messages and what they mean.<br />

Firefox error message Explanation<br />

Unterminated string literal <strong>Missing</strong> opening or closing quote mark:<br />

var name = Jane' ;<br />

Error also appears with mismatched quote marks:<br />

var name = 'Jane";<br />

<strong>Missing</strong> ) after argument list <strong>Missing</strong> closing parenthesis when calling a function or method:<br />

alert('hello' ;<br />

<strong>Missing</strong> ) after condition <strong>Missing</strong> closing parenthesis within a conditional statement:<br />

if (x==0<br />

<strong>Missing</strong> ( before condition <strong>Missing</strong> opening parenthesis within a conditional statement:<br />

if x==0)<br />

<strong>Missing</strong> } in compound<br />

statement<br />

470 javascript & jquery: the missing manual<br />

<strong>Missing</strong> closing brace as part of conditional loop:<br />

if (score == 0) { alert('game over'); // missing }<br />

on this line<br />

<strong>Missing</strong> } after property list <strong>Missing</strong> closing brace for <strong>JavaScript</strong> object:<br />

var x = { fName: 'bob', lName: 'smith' // missing<br />

} on this line<br />

Syntax Error General problem that prevents <strong>JavaScript</strong> interpreter from<br />

reading the script.<br />

<strong>Missing</strong> ; before statement Lets you know when you’ve run two statements together on<br />

a single line, without separating them with a semicolon. You’ll<br />

also see this when you incorrectly nest quotation marks:<br />

var message='<strong>The</strong>re's an error here.';<br />

<strong>Missing</strong> variable name Appears if you attempt to use a <strong>JavaScript</strong> reserved word (see<br />

page 47) for a variable name:<br />

var if="Syntax error.";<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!