Query string parameters

Introduction

In this lesson we will look at:

  • Retrieving parameters from the query string.
  • Passing variables to other pages in the query string.

Lesson Exercise Link

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 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");
View Video

Code from the video.

Adding parameters

In this video, we will add a variable to the href value in an <a> tag, retrieve it from the query string on a separate page, and then use its value in an API call.

View Video

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.