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

Chapter 11. The Global Object and Statements > Controlling How a Script Runs

Controlling How a Script Runs

In various parts of this book, ranging from document.write to event and error handling, I discuss various options for guiding your script to do what you want it to do. However, there are a few techniques you can use for driving your scripts in the right direction. I collect a couple of them here, though in reading other parts of this book, you will certainly pick up a few more.

As far as the statements covered in this chapter exclusively, many of them relate to one another. You can use break and continue to exit loops. You can use throw to exit quickly out of a try code block directly to the catch or finally code blocks. You can nest loops and conditional statements, one within another, as necessary. You can use flags to communicate between one loop and another, as the ineq function example does in Chapter 1, “Object().” The var statement, although optional in many cases, is recommended to declare all variables as a matter of good programming practice. The const keyword is a powerful tool, but should be understood before using. Otherwise, you may find you have created a constant in a way that was not intended.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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