Introduction
In this lesson, we will look at the following:
- Retrieving parameters from the query string.
- Passing variables to other pages in the query string.
Retrieving parameters
In this video, we will look at how we can retrieve parameter values (essential variables) from the query string using code like the one below:
// get the query string
const queryString = document.location.search;
// create an object that will allows us to access all the query string parameters
const params = new URLSearchParams(queryString);
// get the id parameter from the query string
const id = params.get("id");
Code from the video.
Adding parameters
In this video, we will add a variable to the href value in an tag, retrieve it from the query string on a separate page, and then use its value in an API call.
Code from the video.
Lesson Task
Brief
There are practise questions in the master branch of this repo.
Attempt to answer the questions before checking them against the answers branch of the repo.