Loading video...

Video Failed to Load

Go Home

If you're still creating and modifying URLs in JavaScript using string concatenation, this is a PSA that there is a better way:

329,459 views • 3 years ago •via X (Twitter)

10 Comments

Steve (Builder.io)'s profile picture
Steve (Builder.io)3 years ago

Read more about using the URL constructor here:

ian.tsx's profile picture
ian.tsx3 years ago

If you prefer the immutable version: new URLSearchParams( Object.fromEntries({ key: "value", }) ) (Not sure if the Object.fromEntries is needed. It works in chrome without, but typescript requires it)

Fatih Aygün's profile picture
Fatih Aygün3 years ago

This is useful sometimes, especially for constructing the pathname component:

Shelton Louis's profile picture
Shelton Louis3 years ago

Keep making these videos. They are becoming very informative. What you just showed me was an eye-opener. I think I should look more into the tools I use everyday.

Url Sweatshirt's profile picture
Url Sweatshirt3 years ago

Damn my first thought for bugs was that you can’t use await outside of an async function.

Steve (Builder.io)'s profile picture
Steve (Builder.io)3 years ago

You can as of recently!

Thai Pangsakulyanont's profile picture
Thai Pangsakulyanont3 years ago

Can also use URLSearchParams directly: `/api/v2/content?${new URLSearchParams({ model, locale, text })}`

Bao Huynh's profile picture
Bao Huynh3 years ago

Amazing video packed with content. I used to look at URL() constructor and wonder “why not just use template string”. Now I have realized the wrongs of mine.

Batuhan's profile picture
Batuhan3 years ago

Definitely like your content! What tool do you use for subtitles?

Anon Dev's profile picture
Anon Dev3 years ago

I love your content 😍

Related Videos