-1

Hi i am trying to create a basic realtime application in socket.io , i have completely setup the server side in node.js and the file "socket.io.js" is also being imported in browser but somehow when i try to connect with socket.io server using let io = io() or let io = io.connect() i get the following error.

Uncaught ReferenceError: Cannot access 'io' before initialization

node.js code:

enter image description here

client code:

enter image description here

Anas khan
  • 174
  • 2
  • 13
  • 1
    This is a duplicate of [Why does a `let` assignment that uses the same variable name in its right-hand side throw a ReferenceError?](https://stackoverflow.com/q/42967145/4642212). Can’t vote-to-close this one because the answer is at score 0. – Sebastian Simon May 20 '20 at 18:32
  • Thank you , it worked by changing let to var – Anas khan May 20 '20 at 19:06
  • 1
    A better way would be to simply use a different variable name, like `connectedIO`. – Sebastian Simon May 20 '20 at 22:24

1 Answers1

0

After reading a comment on this post i fixed the issue by changing the let with var keyword.

Anas khan
  • 174
  • 2
  • 13