Why does Chrome always say “Error, localhost refused to connect” when I’m trying to run code in Vscode?

I was just learning basic stuff in an online course but when I tried something simple like Console.log "Hello" (I’m only a beginner) Chrome just said “Localhost refused to connect”.
Please tell me how to fix this.