Your problem is not with setTimeout, you need to learn how to write evented code because that is how javascript works and you're going to encounter this problem in different contexts. Passing in a closure to setTimeout usually suffices though, it's just slightly uglier than a normal "sleep" call.
If you really, really wanted to you could create a busy wait sleep function, but it's an awful idea and you should never do it.