Are You Using a Reserved Word? A Possible Reason For Your JavaScript Syntax Errors

Are You Using a Reserved Word? A Possible Reason For Your JavaScript Syntax Errors

In this article, we are revisiting our old friend JavaScript. We know how temperamental our friend can be, so when we visit JavaScript it's nice to know what to do and not to do.

Knowing what to do will help us avoid offending JavaScript and getting a nasty "Syntax Error."

Visiting JavaScript is no different than meeting any distinguished diplomat, they expect to be treated in a certain manner without having to give you a lesson in etiquette.

Diplomats leave the details of teaching proper protocols to their designated staff. JavaScript leaves it up to web developers, that are willing to set the stage.

I am one of those programmers that enjoy it when things go smoothly, so here's a helpful hint that will help you avoid an unwanted "Syntax Error."

Why JavaScript is "Offended" When You Use Reserved Words

It is only fitting to respect the rules of the Royals if they invite you to dinner. Otherwise, how can you engage them in a conversation that could potentially change your life and the outcomes of people or projects that you champion?

JavaScript is no exception. When you ask JavaScript to name values that are important for your functions to hold, it expects you to exclude Reserved Words. JavaScript is offended when using these terms and will give you a Syntax Error.

If you're interested in why JavaScript rejects their use, keep reading after the diagram.

In JavaScript you cannot use these reserved words as variables, labels, or function names:

Chart Information via w3Schools

Words marked with* are new in ECMAScript 5 and 6.

JavaScript is often used together with Java. You should avoid using some Java objects and properties as JavaScript identifiers:







Why JavaScript Has Reserved Words

Binding names can be any word. Digits can be part of binding names—catch22 is a valid name, for example—but the name must not start with a digit. A binding name may include dollar signs ($) or underscores (_) but no other punctuation or special characters. via Eloquent JavaScript

Binding names allow you to hold your values in place, they are like superglue, only you don't get your hands sticky, just the expressions and arguments.

Also, JavaScript is constantly evolving, and reserving these words will help the future development and progress of this programming language.

This isn't meant to be an exhaustive article, just a helpful tip if you get a Syntax Error that you don't understand.

Further reading can be found here:

With these words, I bid you...

Happy Coding