Not sure why the script doesn't execute after .then
abc().then(function(result) {
  var fetch_os = localStorage.getItem('os');
  console.log(fetch_os);
});
function abc() {
  localStorage.setItem('os', 'linux');
  return;
}UPDATE: I think maybe I haven't explained it well. Although was trying to keep it summarised and short. Here is the full code for this issue.
$(document).on('change', '#metamask-eth-paths', function(e) {
  $('.popup-loader-main-wallet').removeClass('hidden');
  $('body').css({
    'cursor': 'wait'
  });
  var path = $(this).val();
  if (path == '2') {
    var path_txt = "Account";
  } else {
    var path_txt = "Account";
  }
  var type = "eth";
  //Test function
  MetaMaskConnect().then(function(result) {
    var meta_address = localStorage.getItem('metamask_address');
    console.log(meta_address);
    if (meta_address !== null) {
      var address = meta_address
      $.ajax({
        url: '/wallet/get-metamask-hd-address/',
        type: 'GET',
        data: {
          type: type,
          address: address,
          add_path: path_txt
        },
        success: function(result) {
          $('body').css({
            'cursor': 'default'
          });
          $('.popup-loader-main-wallet').addClass('hidden');
          if (result) {
            $('#hd-section').empty();
            $('#hd-section').append(result.response_html);
            $("#hd-wallet-modal").modal('show');
          }
        },
        error: function(error) {
          return false
        }
      })
    } else {
      $('body').css({
        'cursor': 'default'
      });
      $('.popup-loader-main-wallet').addClass('hidden');
      $('#hd-section').empty();
      $('#hd-section').append('<h3>An error occured please try again later</h3');
    }
    console.log(meta_address);
  });
  return;
});
function MetaMaskConnect() {
  connectWindow = null
  if (connectWindow == null) {
    connectWindow = window.open("http://localhost:3300");
  } //
  window.addEventListener("message", (event) => {
    if (event.origin !== "http://0.0.0.0:8033") {
      console.log("1")
    }
    if (event.data == null) {
      console.log("2")
    }
    if (event.data !== null && event.origin == "http://0.0.0.0:8033") {
      console.log("3")
      window.removeEventListener("message", event, true);
      connectWindow.postMessage("address_request", "http://localhost:3300");
      window.addEventListener("message", (event) => {
        if (event.origin !== "http://0.0.0.0:8033")
          console.log("4")
        if (event.data == null) {
          console.log("5")
        } else {
          console.log("6")
          var address = event.data;
          console.log("Address: " + address)
          window.removeEventListener("message", event, true);
          //remove old localStorage param
          localStorage.removeItem('metamask_address');
          //add new localStorage param
          localStorage.setItem('metamask_address', address);
          //var result = true;
          return;
        }
      }, false);
    }
    return;
  }, false);
  return true;
}UPDATE:
I have added return Promise which made the code fully execute.
return Promise.resolve("Success");
 
    