Home > front end >  What are the benefit of assigning function results to variables vs calling inline?
What are the benefit of assigning function results to variables vs calling inline?

Time:10-16

I'm learning firebase. in many code examples I see something like this

const auth = getAuth();

await signInWithPopup(auth, provider);

while in firebase web codelab they call getAuth directly

await signInWithPopup(getAuth(), provider);

same thing with getFirestore.
so which one is the correct way of doing it and if they are both same what is better practice?

edit: when I need to use auth object more than once will I get any performance benefits by calling getAuth once and asigning it to a variable?

CodePudding user response:

These two code examples are functionally the same. The first example is simply more verbose.

CodePudding user response:

If you don't need to reuse the auth variable, then you can simply call it directly.

It doesn't have any significant difference in this case.

  • Related