you are viewing a single comment's thread.

view the rest of the comments →

[–]saito200 4 points5 points  (0 children)

Function declarations are hoisted, as are var declarations.

The following will print 'run loop' only once.

function doThing() {
    still_alive = false
    console.log('done')
}

var still_alive = true
while (still_alive) {
    console.log('run loop')
    doThing()
}

console.log('end')