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

Chapter 6. Controlling Your Code I: Test... > Debugging and Troubleshooting Script...

Debugging and Troubleshooting Script Problems

Giving switch() a Break

When I include a switch() statement in my code, JavaScript always runs the default statements, no matter what the value of the expression.

The cause of this behavior is the lack of one or more break statements at the end of each set of case statements. The break statement tells JavaScript to bail out of the switch() construction. If you don't use break, JavaScript continues to process the rest of the cases and eventually runs the statements associated with wither the final case or the default case.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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