Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap

Q1613 How can I exit a function in Javascript?

You are here: irt.org | FAQ | JavaScript | General | Q1613 [ previous next ]

By using the return statement. For example, the following function exits as soon as the counter has reached 100:


<title>return statement</title>


<script language="JavaScript"><!--
function count() {
  for (var counter=0;;counter++) { // an infinite loop
     document.write(counter + '<br>');
     if (counter == 100) return;




©2016 Martin Webb