Look at the following code :
var server = net.createServer(function(socket) {
//Code block A
socket.on('connect', function() {
//Code block B
})
socket.on('data' , function (data){
//Code C
});
});
Is there a chance code block A will be executed and code block B won’t and vice versa?
And if so, in what cases?
For counter example : Once code A has been executed Code C can run multiply time, without Code A ever running again.
Well, providing you call
.listen(), I think you’ll find that You get an order of:Furthermore, A will never begin execution after B as the socket reference that B is bound to is located within the scope of closure A.
@Joe, I also think this sounds interview’y, but what the hey!