Helping ordinary people create extraordinary websites!
GET OUR NEWSLETTER
Your Email:
 

Essential Javascript -- A Javascript Tutorial

By Patrick Hunlock
2007-12-02


Special Keywords

Javascript has a few pre-defined variables with special meaning.

NaN -- Not a Number (Generated when an arithmetic operation returns an invalid result). NaN is a weird construct. For one, it is NEVER equal to itself so you can't simply check to see if 3/'dog' == 'NaN'. You must use the construct isNaN(3/dog) to determine if the operation failed. In boolean operations NaN evaluates to false, however 0 also evaluates to false so use isNaN. Since NaN is never equal to itself you can use this simple trick as well:

if (result != result) { alert('Not a Number!'); }

Infinity is a keyword which is returned when an arithmetic operation overflows Javascript's precision which is in the order of 300 digits. You can find the exact minimum and maximum range for your Javascript implementation using Number.MAX_VALUE and Number.MIN_VALUE.

null is a reserved word that means "empty". When used in boolean operation it evaluates to false.

Javascript supports true and false as boolean values.

If a variable hasn't been declared or assigned yet (an argument to a function which never received a value, an object property that hasn't been assigned a value) then that variable will be given a special undefined value. In boolean operations undefined evaluates as false. Here's an example…

function doAlert(sayThis) {
   
if (sayThis===undefined) { // Check to see if sayThis was passed.
      sayThis
='default value'; // It wasn't so give it a default value
   
} // End check
   alert
(sayThis); // Toss up the alert.
}



Tutorial Pages:
» Essential Javascript -- A Javascript Tutorial
» Getting Started
» In-Line Javascript
» External Javascript
» Javascript is case sensitive
» Output (writeln)
» Output (alert)
» Output (getElementById)
» Input (One Click To Rule Them All)
» Input (User Input)
» Javascript is an Event Driven Language
» Comments
» Variables
» Variable Scope
» Special Keywords
» Arithmetic Operators
» Logical and Comparison Operators
» JavaScript Conditionals: IF
» JavaScript Conditionals: SWITCH
» JavaScript Conditionals: Shorthand Assignment
» JavaScript Conditionals: Ternary Operators
» JavaScript Loops: FOR
» JavaScript Loops: FOR/IN
» JavaScript Loops: WHILE
» Bringing It All Together
» DHTML: Dynamic HTML
» Conclusion


copyright © 2006, 2007 by Patrick Hunlock


 | Bookmark
Related Tutorials:
» JavaScript Debugging Techniques with Firebug
» Striped Tables Using JavaScript
» Opening PDFs in a New Window with JavaScript
» Submit Forms Conditionally using JavaScript
» How to Setup a Randomising Function
» Introduction to JavaScript Tutorial

Advertise with Us!


Tutorials Scripts Web Hosting Developer Manuals
Resources