Why does this JavaScript code print an unexpected result? I came across this small JavaScript example and the output surprised me. for (var i = 0; i…