Member["email"] is not accessing outside the function

Hey

var uemail;

window.MemberStack.onReady.then(function(member) {   

   uemail = member['email'];

  console.log(typeof(member["email"]));

  

});

now uemail is not storing the values , and it returns undefine

Hey Vishv :wave:

Welcome, and thank you for posting in the forum! :partying_face:

I just tested the following code and its working for me. Also it comes back as a string. :smiley:

 var uEmail;
 MemberStack.onReady.then(function(member) {   
  uEmail = member['email'];
  console.log(typeof(uEmail));
 });
var uEmail;
 MemberStack.onReady.then(function(member) {   
  uEmail = member['email'];
  console.log(typeof(uEmail));
 });
```  console.log(uEmail); //it prints undefined bcz it outside of the function
Thats the problem

Im only getting undefined when im logged out. Can you provide more information please?

See i m getting the data inside the function but not outside

Hey Vishv :wave: Try doing something like this. The reason you are getting undefined is that the console.log is running before the Memberstack code.

 var uEmail;
 MemberStack.onReady.then(function(member) {   
  uEmail = member['email'];
  console.log(typeof(uEmail));
 }).then(() => {   
  console.log(typeof(uEmail));
// your additional code here
 });

Yehh I Got it
Thanks

1 Like