Need example usage of GetState (websocket)

Would you mind explaining what each line does? I’m extraordinarily new to APIs and am also looking for any learning resources you might be able to recommend.
I assume that any line preceded by ‘var’ sets a variable. emit (from the api documentation page) seems to be how one communicates requests to volumio, the only real line I dont follow I suppose is the last one.