Skip to content

Tag: reserved-words

Determine if a word is a reserved Javascript identifier

Is it possible in Javascript to determine if a certain string is a reserved language keyword such as switch, if, function, etc.? What I would like to do is escaping reserved identifiers in dynamically generated code in a way that doesn’t break on browser-specific extensions. The only thought coming to my mind is using eval in a try-catch block and