title: Uncaught TypeError at WebSocket.ws.onmessage
body: <p>I'm new to web socket and I'm trying to get my feet wet by trying out the code below.</p>
  
  <pre><code>var id=0; 
  var symbol=""; 
  var interval=""; 
  var open_time=0; 
  var open=0; 
  var high=0; 
  var low=0; 
  var close=0; 
  
  var ws = new WebSocket('wss://stream.bybit.com/realtime');
  
  ws.onopen = function(){
      //console.log("Socket has been opened!");
      ws.send('{"op":"subscribe","args":["kline.BTCUSD.1m"]}');
  }
  
  ws.onmessage = function(msg){
      //console.log(msg.data);        
  
      var obj = JSON.parse(msg.data);
      //console.log(obj.data);
  
      id = obj.data.id;
      symbol = obj.data.symbol;
      interval = obj.data.interval;
      open_time = new Date(obj.data.open_time * 1000);
      open = obj.data.open;
      high = obj.data.high;
      low = obj.data.low;
      close = obj.data.close;
  
  }
  </code></pre>
  
  <p>And although the code above works just fine, but I still can't figure out the error in console log below:</p>
  
  <pre><code>main.js:28 Uncaught TypeError: Cannot read property 'id' of undefined
      at WebSocket.ws.onmessage (main.js:28)
  </code></pre>
  
  <p>I hope somebody can give me an idea why the <code>onmessage</code> function <code>cannot read the property "id" of undefined</code> on the first iteration but no problem reading it on the succeeding loops.</p>