I am getting this undefined
error in my node js written program. This was the line that was causing the issue
sockets[index].notification = 1;
So in order to resolve this, I did this
if ( typeof sockets[index].notification !== 'undefined' ) {
sockets[index].notification = 1;
}
But it still gave the same error
if ( typeof sockets[index].notification_acc_on !== 'undefined' ) {
^
TypeError: Cannot read property 'notification' of undefined
at Socket.<anonymous> (/var/www/html/server.js:506:56)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:597:20)
How can I check and handle this so if the variable isn't set, my program doesn't crash at least? In short I want to prevent the crash