const params = new URLSearchParams(window.location.search); const something = decodeURIComponent(params.get('hi')); // or shorter, no need to use variables decodeURIComponent((new URLSearchParams(window.location.search)).get('hi'))