0

Following is JavaScript for implementing Firebase.

import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';

const config = { }

firebase.initializeApp(config);

export const auth = firebase.auth();
export const firestore = firebase.firestore();

const provider = new firebase.auth.GoogleAuthProvider();
provider.setCustomParameters({ prompt: 'select_account' });
export const signInWithGoogle = () => auth.signInWithPopup(provider);


export default firebase;

What is the difference between the following codes? Why does it make sense to assign a function vs non-function?

Right way

export const signInWithGoogle = () => auth.signInWithPopup(provider);

Wrong-way

export const signInWithGoogle = auth.signInWithPopup(provider);

Michael
  • 19
  • 1
  • 1
  • Look into what an "arrow function" is. The snippets are not wrong vs. right, the two snippets simply do fundamentally different things. – luk2302 Feb 19 '21 at 14:33
  • https://stackoverflow.com/questions/24900875/whats-the-meaning-of-an-arrow-formed-from-equals-greater-than-in-javas – luk2302 Feb 19 '21 at 14:34
  • 1
    *"Why does it make sense to assign a function vs non-function?"* Because the second one, `xport const signInWithGoogle = auth.signInWithPopup(provider);`, **calls** `auth.signInWithPopup` immediately and assigns its return value to `signInWithGoogle`. But the first one, `export const signInWithGoogle = () => auth.signInWithPopup(provider);`, *creates a function* and assigns that function to `signInWithGoogle`. *Later*, if `signInWithGoogle` is called, it will call `auth.signInWithPopup(provider);` and return the result. – T.J. Crowder Feb 19 '21 at 14:35

0 Answers0