Quick Tip: Optimized URL handling

There are a few potential issues with the following code:

  • The URI variables aren't being encoded properly

  • Our editor or commit hooks might format this to a multi-line string, which would add a new line character to the URL

  • And we might accidentally use the wrong character ? instead of & to concat new query params. We're human, we make mistakes.

Good news! There's a better way to handle all of these issues with a helpful Web API class, URL✨

On top of being a safer way to create and manage our URLs in the browser, it's more readable and maintainable for other devs working on the same project.

Thanks to Steve Sewell at Builder.io for his short video on this topic. Follow his channels to discover other great JS/TS tips.

category

tags

development
javascript