| Input Type | Result |
|---|---|
| Undefined | No Conversion |
| Null | No Conversion |
| Boolean | No Conversion |
| Number | No Conversion |
| String | No Conversion |
| Object | Return a default value for the Object. The default value of an object is retrieved by calling the internal [[DefaultValue]] method of the object, passing the optional hint PreferredType |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Queue() { | |
| this.values = []; | |
| this.count = 0; | |
| } | |
| Queue.prototype.enqueue = (newValue) => { | |
| this.values[this.count] = newValue; | |
| this.count++; | |
| } |
| Input Type | Result |
|---|---|
| Undefined | NaN |
| Null | +0 |
| Number | No Conversion |
| Boolean | The result is 1 if the argument is true. The result is +0 if the argument is false. |
| ... | ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const db = firebase.firestore(); | |
| const usersRef = db.collection('users'); // Get a reference to the Users collection; | |
| // Set the specific user's online status to true | |
| usersRef | |
| .doc(userId) | |
| .set({ | |
| online: true, | |
| }, { merge: true}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const oldRealTimeDb = firebase.database(); | |
| oldRealTimeDb | |
| .ref('/some/random/key') // Making a reference to a key-value pair in the old real-time database structure | |
| .onDisconnect() // Setting up the onDisconnect hook | |
| .set('This string will be set for the referenced key once the client disconnects!'); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const functions = require('firebase-functions'); | |
| const Firestore = require('@google-cloud/firestore'); | |
| const firestore = new Firestore(); | |
| exports.onUserStatusChanged = functions.database | |
| .ref('/status/{userId}') // Reference to the Firebase RealTime database key | |
| .onUpdate(event => { | |
| const usersRef = firestore.collection('/users'); // Create a reference to the Firestore Collection | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const firestoreDb = firebase.firestore(); | |
| const oldRealTimeDb = firebase.database(); | |
| const usersRef = firestoreDb.collection('users'); // Get a reference to the Users collection; | |
| const onlineRef = oldRealTimeDb.ref('.info/connected'); // Get a reference to the list of connections | |
| onlineRef.on('value', snapshot => { | |
| // Set the Firestore User's online status to true | |
| usersRef | |
| .doc(userId) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const firestoreDb = firebase.firestore(); | |
| const oldRealTimeDb = firebase.database(); | |
| const usersRef = firestoreDb.collection('users'); // Get a reference to the Users collection; | |
| const onlineRef = oldRealTimeDb.ref('.info/connected'); // Get a reference to the list of connections | |
| onlineRef.on('value', snapshot => { | |
| oldRealTimeDb | |
| .ref(`/status/${userId}`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const handler = { | |
| get: function() { | |
| console.log('A value has been accessed'); | |
| } | |
| } | |
| const initialObj = { | |
| id: 1, | |
| name: 'Foo Bar' | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const handler = { | |
| get: function(obj, prop) { | |
| console.log('A value has been accessed'); | |
| return obj[prop]; // Return the value stored in the key being accessed | |
| } | |
| } | |
| const initialObj = { | |
| id: 1, | |
| name: 'Foo Bar' |