Bird
0
0

Which JavaScript statement correctly initializes a WebSocket connection to ws://192.168.1.10:8080 on a Raspberry Pi?

easy📝 Syntax Q3 of 15
Raspberry Pi - Web Server and API
Which JavaScript statement correctly initializes a WebSocket connection to ws://192.168.1.10:8080 on a Raspberry Pi?
Aconst socket = new WebSocket('ws://192.168.1.10:8080');
Bconst socket = WebSocket.connect('ws://192.168.1.10:8080');
Cconst socket = new WebSocket.connect('ws://192.168.1.10:8080');
Dconst socket = WebSocket('ws://192.168.1.10:8080');
Step-by-Step Solution
Solution:
  1. Step 1: Use the WebSocket constructor

    The correct way to create a WebSocket client in JavaScript is by using the new WebSocket(url) syntax.
  2. Step 2: Verify the URL format

    The URL must be a string starting with ws:// or wss:// followed by the IP and port.
  3. Final Answer:

    const socket = new WebSocket('ws://192.168.1.10:8080'); -> Option A
  4. Quick Check:

    Constructor usage and URL format correct [OK]
Quick Trick: Use 'new WebSocket(url)' to create connection [OK]
Common Mistakes:
MISTAKES
  • Calling WebSocket as a function without 'new'
  • Using incorrect method like WebSocket.connect
  • Incorrect URL string format

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes