
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
110
|
Chapter 4: Primitive Datatypes
If we use undefined instead of null:
var title = "My Holiday Photos";
var description = undefined;
the initialization code has no way to tell whether the interpreter set description’s
value automatically or we set it intentionally. The distinction is subtle, but it is valu-
able in large programs. Here we expand our earlier initialization code to display an
error message when no description value has been set.
// If there's a valid description...
if (description = = = undefined) {
trace("WARNING: No description value was specified!");
} else if (description != = = null) {
// ...create description text field.
}
By distinguishing between undefined and null in our initialization code, we can pro-
vide accurate debugging feedback and catch potential programmer oversight. For
another example of real-world
null usage, see the TextFormat class’s constructor
parameters in the Language Reference.
Onward!
You’ve learned a lot more so far than you may have realized. We’ve built a solid
foundation for the advanced topics coming in later chapters. If you haven’t mastered
all the details yet, don’t worry. Your training will come back to you when you need it.
Keep the faith during the next chapter, in which you’ll learn how to merge and trans-
form data. Following that, ...