Hello this will be my first of many posts i'm sure because this seems like such a great site. Well anyway i'm sort of new to the scene, the web development scene that is but i really want to start
learning html 5, so up to this point I have a really decent understanding of x/html, css and xml so now i'm trying to get a handle on javascript before I dwell into html 5. So I've been reading this book called "Eloquent Javascript" which supposedly is a good introduction to the language, but maybe its me but man I am having such a hard time learning this stuff. I am that kind of guy who wants to
know how and why something works, instead of just memorizing the formula and using it when I need to, and so far this book doesn't do that for me at all. But anyway I'm on page 36 and and the
book throws out an example of a function using the string and the math.round objects. Here is the example:

function zeroPad(number, width) {
var string = String(Math.round(number));
while (string.length < width)
string = "0" + string;
return string;
}


Ok now the book then goes on to explain that math.round is a function that rounds a number and the string is a function that converts its argument to a string, I get that but the part
that is confusing to me is this section:

while (string.length < width)
string = "0" + string;


The reason I am confused is that say for instance I use print(zeroPad(2, 4)); I obvuously will get 0002 but I don't see how because when I look at this (and ofcourse I now I'm wrong)
while string.length (which is 1 because the number 2 is a string of 1 in my head ) is less then ( < ) width (which is 4) so moving along to string = "0" + string; must mean "02" as the answer.
So whats really confusing to me is how and does the string function just suddenly decides that its going to return a string length of "4"? I know this was fairly long and I apologize but I would really
appreciate your help ladies and gents. So far it has been a pain for me to say the least to learn javascript compared to the other languages I mentioned, but in a way for my benefit it feels like a goodthing