Introduction
In this lab, we will explore the fundamentals of JavaScript programming language. You will learn how to write basic syntax, manipulate data types, use conditional statements, loops, and functions. By the end of this lab, you will have a solid foundation in JavaScript and be able to create simple programs.
Retrieving Base URL
To retrieve the base URL from a given URL, follow these steps:
- Open the Terminal/SSH.
- Type
nodeto start practicing coding. - Use the following JavaScript function to get the current URL without any parameters or fragment identifiers:
const getBaseURL = (url) => url.replace(/[?#].*$/, "");
- Replace
urlwith the URL you want to retrieve the base URL from. - The function will remove everything after either
'?'or'#', if found, and return the base URL. - Here's an example:
getBaseURL("http://url.com/page?name=Adam&surname=Smith");
// 'http://url.com/page'
Summary
Congratulations! You have completed the Get Base URL lab. You can practice more labs in LabEx to improve your skills.