diff --git a/files/en-us/web/api/url/searchparams/index.md b/files/en-us/web/api/url/searchparams/index.md index b83b73b49d06625..05ca9f39b43c0aa 100644 --- a/files/en-us/web/api/url/searchparams/index.md +++ b/files/en-us/web/api/url/searchparams/index.md @@ -18,14 +18,14 @@ A {{domxref("URLSearchParams")}} object. ## Examples -If the URL of your page is -`https://example.com/?name=Jonathan%20Smith&age=18` you could parse out -the `name` and `age` parameters using: - ```js -let params = new URL(document.location).searchParams; -let name = params.get("name"); // is the string "Jonathan Smith". -let age = parseInt(params.get("age")); // is the number 18 +const params = new URL("https://example.com/?name=Jonathan%20Smith&age=18") + .searchParams; +const name = params.get("name"); +const age = parseInt(params.get("age")); + +console.log(`name: ${name}`); // name: Jonathan Smith +console.log(`age: ${age}`); // age: 18 ``` ## Specifications