p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning JavaScript 5th Edition (http://p2p.wrox.com/forumdisplay.php?f=793)
-   -   Ch3. The do..while loop. (no semicolon); (http://p2p.wrox.com/showthread.php?t=95407)

Wilfred Desert January 7th, 2016 08:02 AM

Ch3. The do..while loop. (no semicolon);
 
On page 82 there's a do-while loop example.

Quote:

var userAge;
do {
userAge = prompt("Please enter your age","")
} while (isNaN(userAge) == true);
and below the author repeats one more time:

Quote:

userAge = prompt ("Please enter your age","")
There's no semicolon at the end of the statement inside the do {} block. As far as I can remember the author stated that it's considered best to always end any statement with a semicolon although it's not a must in most cases.

Was the omission of ; intentional? It seems so considering that in both the 4th and 5th editions there's no semicolon.
And there's also a repetition of that line below which doesn't contain a semicolon either.
Of course, you might say that it's not even a mistake. I just want to understand whether or not a semicolon was meant. If not - then it's a minor sign of incosistency.

snowcrasher555 January 8th, 2016 02:46 PM

I think you are right, it should have a semi-colon as far as best practices are concerned, but most interpreters are smart enough to work without a semi-colon there. Still, it should not have been omitted.

jmcpeak January 8th, 2016 02:47 PM

Even though the semi-colon is missing in the 4th Edition, it is not intentional in the 5th. It's a code sample that I missed. There should be a semi-colon at the end of that statement.


All times are GMT -4. The time now is 11:59 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.