This is because currentMember.getMember() needs to be called at some point and only then will it run and fetch the member’s name.
Calling it within the onReady function runs the code when the page is loaded.
So when you log the member name, it will return the default value which in this case is Hello world since the currentMember.getMember() is not being called.
If you want the code to be outside of the onReady function, you can write it under another function, something like:
import { currentMember } from ‘wix-members-frontend’;
var FullName = “Hello world”
function gemember () {
currentMember.getMember()
.then(async(member) => {
const id = member._id;
FullName = await ${member.contactDetails.firstName} ${member.contactDetails.lastName};
console.log(id) //This works
console.log(FullName) //This works
return member;
})
.catch((error) => {
console.error(error);
});
}
$w.onReady(function () {
getMember();
console.log(FullName) // Returns ‘HELLO WORLD’ vs results from getMember()
});```