Getting the Account Display Name in Windows 10 Apps using JavaScript

Below is a sample JavaScript code snippet demonstrating how to get the account display name from the Windows 10 Universal Windows Platform App using WinJS.

How to Get the Account Display Name in Windows 10 Apps using JavaScript ?

function returnDisplayNameAC() {
// Check if the privacy settings in Windows 10 allows the apps to get the name
        if (Windows.System.UserProfile.UserInformation.nameAccessAllowed) {
            Windows.System.UserProfile.UserInformation.getDisplayNameAsync().done(function (returnData) {
                if (returnData) {
                    return returnData;
                } 
            });
        } else {
            return "Access to name is disabled by Privacy Setting or Group Policy of your Windows";
        }
    }