Errors 10 exercises
Problem

Fixing "X is Possibly Null Or Undefined"

Here we start by declaring a variable searchParams that is initialized with the URLSearchParams class instance:


const searchParams = new URLSearchParams(window.location.search);

This object permits us to invoke the get method, which is used to retrieve the id parameter. The `get

Loading exercise

Transcript

00:00 In this exercise, we have some search params here where we're saying search params equals new URL search params, window.location.search. This returns a URL search params type or class or class instance, and that you can then call get on. And we're getting the search params ID, which then we get back as string or null.

00:19 And then we're console logging it to ID two upcase. Your job is to work out why this error is occurring, ID is possibly null, and to figure out how we can make this better. There are a few ways of doing this. A couple are TypeScript only, a couple are runtime,

00:37 and most of them will change the behavior of this setup too. So yeah, that's your job. See if you can fix it. Good luck.