It's an illusion.
The anon function function(){bar = 1} is not actually executed with this syntax. As per the documentation of $.when, if one of its argument is not a promise then it is treated as a promise that has been resolved with the argument itself as the resolution value.
That is, the code is equivalent to
var f = function(){bar = 1}; // obviously not executed yet
var d = $.Deferred().resolve(f); // still not executed
$.when(d).then(function(){
console.log('print ' + bar)
})
You can check that this is in fact what happens by making the callback do something visible and having your chained success handler accept an argument:
$.when(function(){alert("invoked!")}).then(function(result){
result(); // only now is the alert displayed
})