Why `queryObjects()` in chrome console returns undefined but then results are printed out?

I executed the function queryObjects(WebSocket.prototype) in chrome console, which was promised to return an array of existing websockets on that page. However the return value is undefined, then after a while the expected result was printed out. What happens?

> queryObjects(WebSocket.prototype)
< undefined
  Array(1)
  ...

It seems that this function has no return value but just prints out the query result.