Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

default

Another point of contention with regard to switch is whether a default case is required. Some believe that a default should always be included even if the default action is to do nothing, as in:

switch(condition) {
    case "first":
        // code
        break;

    case "second":
        // code
        break;

    default:
        // do nothing
}

You’re likely to find open source JavaScript code following this pattern, including default and just leaving a comment that nothing should happen there. Although no style guides are explicit about this, both Douglas Crockford’s Code Conventions for the JavaScript Programming Language and the Dojo Style Guide include default as part of their standard switch statement format.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint