• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 23. Cookies and Creating Your Ow... > Setting Default Property Values

Setting Default Property Values

In NS4+ and IE4+, you can specify default values for properties in a constructor using this syntax, where the default value appears as the second term in each OR expression (which uses the JavaScript || operator):

function friend(name, phone, rank) 
{ 
    this.name = name || "George"
					this.phone = phone || "555-1212"
					this.rank = rank || 10 
} 


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint