Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScritp Semicolons - When to (Ab)Use?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi, I get a &quot;function does not always return a value&quot; error when calling a function using Communicator 4.04.(I don't get it with IE or Navigator.) Here is a snippet of the function code:<br>function htmlGen() {<br>var ret;<br>ret = &quot;&lt;SOME HTML&gt;&quot;;<br>return ret;<br>}<br>When I run this on Communicator 4.04, a JavaScript alert box pops up, displays the last line in the function and highlights the semicolon:<br>return ret<font color=red>;</font><br>^<br>----------¦<br>and says &quot;function does not always return a value.&quot;<br>Is my semicolon confusing the JavaScript interpreter?<br>Aren't all JavaScript lines supposed to end in a semicolon? I've seen some that do, some that don't - what's the rules?<br><br>Pleez help, I'm trying to make my pages work on a variety of browsers...<br><br>Also, is there a good book or source that explains the different nuances of the various browsers and is there a set of JavaScript commands/rules that is &quot;browser-safe&quot;...<br><br>Thanks, Mikey at the CoffeyShop
 
Semicolons are great tools to help readability, and to prepare you for programming in Java (if you want to)...<br>Semicolons are only needed when you have to js statements on the same line. I think you could geneerate some errors with semicolons (not sure about your particular question) by putting them after brackets and such:<br><br>function darg()<font color=red>;</font><br>{...}<br><br>would cause an error.<br><br><A HREF="mailto:jared@aauser.com">jared@aauser.com</A>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top