Skip to main content

Valid JavaScript variable names

I’ve been working on a little library to help build little JavaScript applications. Something to fill the gap for me between little scripts and reaching for a framework like Svelte.

While designing the API, I’ve found myself searching for obscure but technically valid JS variable names to distinguish my library from the standard HTML element properties. Is @id valid? What about $id? Can I use a :?

These questions are easy to answer by opening the console, but wouldn’t it be nice to have a little tool to validate JavaScript variable names? Thankfully it already exists: Mathias Bynen’sJavaScript variable name validator.

With it you can quickly validate a variable while maintaining your flow. And if you’re curious as to why, he has an article explaining the specifications. While writing this, I noticed that the main site has a bunch of other little tools for you to checkout. (Pardon the name 🙊)

Up the web!