In a real-time chat application, you need to implement a feature that notifies users when someone is typing a message. How would you accomplish this using JavaScript?
- Use AJAX polling to check typing status
- Use WebSocket to send typing status
- Use oninput event listener
- Use setTimeout and clearTimeout for delay
Using WebSocket allows real-time communication between clients and the server, making it ideal for notifying users when someone is typing. setTimeout and clearTimeout are more suitable for handling delays and timeouts, not real-time updates. AJAX polling introduces unnecessary overhead and delays. The oninput event listener is used for detecting input changes, not real-time status updates.
Loading...
Related Quiz
- The ___________ statement in SQL is used to remove one or more rows from a table.
- The _______ index stores a copy of the indexed columns along with the index data structure.
- How would you optimize a SQL query that is running slow on a large dataset?
- How does sharding contribute to scalability in NoSQL databases?
- Imagine you're tasked with building an e-commerce platform using Node.js. How would you handle secure payment processing and data encryption to ensure customer data privacy?