IT박스

JavaScript로 예약 된 키워드

itboxs 2020. 6. 1. 19:25
반응형

JavaScript로 예약 된 키워드


어떤 JavaScript 키워드 (함수 이름, 변수 등)가 예약되어 있습니까?


Google에서 가장 인기있는 정보가 아닌 실제 정보 소스에 연결해야합니다.

http://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Reserved_Words

JScript 8.0 : http://msdn.microsoft.com/en-us/library/ttyab5c8.aspx


다음은 JavaScript로 예약 된 모든 키워드를 포함하는시입니다. 현재 정직하고 점수를 매기려는 사람들을 위해 최선을 다하고 있습니다.

Let this long package float, 
Goto private class if short.
While protected with debugger case,  
Continue volatile interface.
Instanceof super synchronized throw, 
Extends final export throws.  

Try import double enum?  
- False, boolean, abstract function, 
Implements typeof transient break!
Void static, default do,  
Switch int native new. 
Else, delete null public var 
In return for const, true, char
…Finally catch byte.

benc의 답변 을 보완하려면 표준 ECMA-262를 참조하십시오 . 이 단어는 공식 예약어이지만 표준을 준수하는 구현은 무시합니다. 가장 많이 사용되는 구현, 즉 Firefox 및 인터넷 익스플로러의 예약어에 대해서는 benc 's answer를 참조하십시오.

EMCAScript-262에서 예약어는 키워드 , 미래 예약어 , NullLiteralBooleanLiteral입니다 . 여기서 키워드

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

미래 예약어 들입니다

abstract  export      interface  static
boolean   extends     long       super
byte      final       native     synchronized
char      float       package    throws
class     goto        private    transient
const     implements  protected  volatile
double    import      public 
enum      int         short

NullLiteral은 이다

null

그리고 BooleanLiteral 들입니다

true
false

방금 JavaScript & jQuery : Missing Manual 에서 이것에 대해 읽었습니다 .

이 예약어 모두가 모든 브라우저에서 문제를 일으키는 것은 아니지만 변수 이름을 지정할 때 이러한 이름을 지우는 것이 가장 좋습니다.

자바 스크립트 키워드 : break, case, catch, continue, debugger, default, delete, do, else, false, finally, for, function, if, in, instanceof, new, null, return, switch, this, throw, true, try, typeof, var, void, while, with .

나중에 사용하기 위해 예약 됨 : abstract, boolean, byte, char, class, const, double, enum, export, extends, final, float, goto, implements, import, int, interface, let, long, native, package, private, protected, public, short, static, super, synchronized, throws, transient, volatile, yield .

브라우저에서 사전 정의 된 전역 변수 : alert, blur, closed, document, focus, frames, history, innerHeight, innerWidth, length, location, navigator, open, outerHeight, outerWidth, parent, screen, screenX, screenY, statusbar, window .


Here is a browser and language version agnostic way to determine if a particular string is treated as a keyword by the JavaScript engine. Credits to this answer which provides the core of the solution.

function isReservedKeyword(wordToCheck) {
    var reservedWord = false;
    if (/^[a-z]+$/.test(wordToCheck)) {
        try {
            eval('var ' + wordToCheck + ' = 1');
        } catch (error) {
            reservedWord = true;
        }
    }
    return reservedWord;
}

None of the current answers warn that regardless of ES-Dialect, browsers tend to have their own lists of reserved keywords, methods etc on top of what ES dictates.

For example, IE9 prohibits use of logical names like: addFilter, removeFilter (they, among others, are reserved methods).

See http://www.jabcreations.com/blog/internet-explorer-9 for a more extensive 'currently known' list specific to IE9. I have yet find any official reference to them on msdn (or elsewhere).


Here is a list from Eloquent JavaScript book:

  • break
  • case
  • catch
  • class
  • const
  • continue
  • debugger
  • default
  • delete
  • do
  • else
  • enum
  • export
  • extend
  • false
  • finally
  • for
  • function
  • if
  • implements
  • import
  • in
  • instanceof
  • interface
  • let
  • new
  • null
  • package
  • private
  • protected
  • public
  • return
  • static
  • super
  • switch
  • this
  • throw
  • true
  • try
  • typeof
  • var
  • void
  • while
  • with
  • yield

benc's answer is excellent, but for my two cents, I like the w3schools' page on this:

http://www.w3schools.com/js/js_reserved.asp

In addition to listing the keywords reserved by the standard, it also has a long list of keywords you should avoid in certain contexts; for example, not using the name alert when writing code to be run in a browser. It helped me figure out why certain words were highlighting as keywords in my editor even though I knew they weren't keywords.

참고URL : https://stackoverflow.com/questions/26255/reserved-keywords-in-javascript

반응형