Getting the User First Name in Windows 10 Apps using JavaScript

Below is a sample JavaScript code snippet demonstrating how to get the user’s first Name from the Windows 10 Universal Windows Platform App using WinJS.

How to Get the User’s first Name in Windows 10 Apps using JavaScript ?

function getUserFirstName() {
    if (Windows.System.UserProfile.UserInformation.nameAccessAllowed) {
        Windows.System.UserProfile.UserInformation.getFirstNameAsync().done(function (data) {
            if (data) {
               return data;
            } 
        });
    } else {
        return "Name cannot be accessed because this functionality is disabled by Privacy Setting or Group Policy in Windows 10";
    }
}