Is there anyway to check that a variable value I receive latter different than the previous one as below: function passData() { var i = Math.random(); getData(i); } function getData(i) { this.i = i; console.log(i); } var button = document.getElementById('button'); button.addEventListener('click', passData, false); Code (markup): In real life there is only two values of variable being received through websocket and I don't know how to separate them. Thank you,
yes you can use array, but if you need to compare only with the last value, then you can use a variable. for example var lastvalue=0; function actionXYZ(value){ // perform comparison of 'value' to 'lastvalue' //do action // in the end, update lastvalue lastvalue=value; } HTML: