Which option correctly describes the behavior of once() compared to on() when reading data from Firebase Realtime Database?
Think about whether the method keeps watching for updates or just fetches data a single time.
once() fetches data a single time and then stops listening. on() sets up a continuous listener that triggers every time data changes.
Which code snippet correctly reads data once from Firebase Realtime Database and logs the value?
const dbRef = firebase.database().ref('users/user1');Check the method that returns a promise and reads data once.
once() returns a promise that resolves with the data snapshot. Passing a callback directly is deprecated. on() sets a listener. get() is a newer method but requires no event type argument.
You are designing a chat app that shows messages and updates them live. Which approach is best for reading messages?
Think about how to keep the chat updated automatically.
on() sets a live listener that updates the UI whenever new messages arrive, which is ideal for chat apps. once() reads data only once and would not update automatically.
What is a key security consideration when using on() listeners in Firebase Realtime Database?
Consider how continuous data access affects security.
on() listeners keep data flowing to clients, so Firebase security rules must carefully control who can read data to prevent leaks.
Which code snippet correctly removes a Firebase Realtime Database on() listener to prevent memory leaks?
const dbRef = firebase.database().ref('users/user1'); function startListening() { dbRef.on('value', callback); } function stopListening() { // What goes here? }
Check the Firebase method to remove listeners.
off() is the correct method to remove listeners added by on(). Other methods do not exist or cause errors.