06.07.2017 Views

Mastering JavaScript

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 1<br />

debug("INFO","Info Message");<br />

debug("DEBUG","Debug Message");<br />

debug("ERROR","Fatal Exception");<br />

In this example, we are intentionally letting the execution fall through to write a<br />

concise switch-case. If levels are either INFO, WARN, or DEBUG, we use the switchcase<br />

to fall through to a single point of execution. We omit the break statement for<br />

this. If you want to follow this pattern of writing switch statements, make sure that<br />

you document your usage for better readability.<br />

Switch statements can have a default case to handle any value that cannot be<br />

evaluated by any other case.<br />

<strong>JavaScript</strong> has a while and do-while loop. The while loop lets you iterate a set of<br />

expressions till a condition is met. The following first example iterates the statements<br />

enclosed within {} till the i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!