javascript - How does this While loop end? - Node Code -


hello, using website 'codeschool.com' , think instructors code has infinite loop in node/javascript code, i'm not certain.

here code:

http.createserver(function(request, response) {   response.writehead(200);   request.on('readable', function () {     var chunk = null;     while( null !==(chunk = request.read())) {       response.write(chunk);     }   });   request.on('end', function() {     response.end();   }); }).listen(8080) 

the instructor says code similar using request.pipe(response);

i understand concept, what's throwing me loop (no pun intended) while loop, how ever end?

request.read() returns slice of available data each time called, until there no more data returned, in case returns null.

at point, chunk equals null , since assignments expressions return assigned value, condition false , therefor while loop ends:

while ( null !== (chunk = null) ) { ... }


Comments