Certain words in JavaScript are reserved, which means you can’t use them as variables, identifiers, or constant names within your program because doing so will cause the code to have unexpected results, such as errors. For example, you’ve already seen the reserved word var in previous examples. Using the word var to do anything but declare a variable can cause an error or other unexpected behavior, depending on the browser. Consider this statement:
// Don't do this!
var var = 4;
The code example won’t result in a direct error to a browser, but it also won’t work as you intended, possibly causing confusion when a variable’s value isn’t what you expect.
The following table includes the words that are currently reserved by the ECMA-262 edition 5.1 specification:
break, delete, if, this, while, case, do, in, throw, with, catch, else, instanceof, try, continue, finally, new, typeof, debugger, for, return, var, default, function, switch, void
Several other words (shown in the following table) are reserved for future use and therefore
shouldn’t be used in your programs:
class enum extends super
const export import
The following table shows the words that are reserved for the future when in strict mode:
implements let private public yield
interface package protected static
No comments:
Post a Comment