List of reserved words in JavaScript

泄露秘密 提交于 2019-12-12 10:49:56

问题


Is there any more complete list than Mozilla's about reserved words?

It lacks words like parseFloat, toString, prototype, etc.


回答1:


parseFloat, toString and prototype are not reserved words. Just because they sometimes have a special meaning, doesn't mean you can't declare variables with their names;

var prototype = "foo"; // no error.

The ES5 standard contains a list of reserved words as well, but it should match the list given by MDN:

break, do, instanceof, typeof, case, else, new, var, catch, finally, return, 
void, continue, for, switch, while, debugger, function, this, with, default,
if, throw, delete, in, try

class, enum, extends, super, const, export, import

It might also be of interest to you that the strict varient of ES5 adds additional words to the reserved list;

The identifiers "implements", "interface", "let", "package", "private", "protected", "public", "static", and "yield" are classified as FutureReservedWord tokens within strict mode code. (section 7.6.1.2).



来源:https://stackoverflow.com/questions/10397951/list-of-reserved-words-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!