SyntaxError: "x" is a reserved identifier

메세지

SyntaxError: The use of a future reserved word for an identifier is invalid (Edge)
SyntaxError: "x" is a reserved identifier (Firefox)
SyntaxError: Unexpected reserved word (Chrome)

μ—λŸ¬ νƒ€μž…

무엇이 잘λͺ»λ˜μ—ˆμ„κΉŒ?

μ˜ˆμ•½μ–΄κ°€ μ‹λ³„μžλ‘œ 쓰인 경우 λ°œμƒν•˜λŠ” μ—λŸ¬μž…λ‹ˆλ‹€. 이 ν‚€μ›Œλ“œλŠ” 엄격(Strict) λͺ¨λ“œμ™€ λŠμŠ¨ν•œ(Sloppy) λͺ¨λ“œμ—μ„œ λͺ¨λ‘ μ˜ˆμ•½μ–΄λ‘œ μ·¨κΈ‰λ©λ‹ˆλ‹€.

  • enum

λ‹€μŒμ€ 엄격 λͺ¨λ“œμ˜ μ½”λ“œμ—μ„œλ§Œ μ˜ˆμ•½μ–΄λ‘œ μ·¨κΈ‰λ©λ‹ˆλ‹€:

  • implements
  • interface
  • let
  • package
  • private
  • protected
  • public
  • static

예제

엄격 λͺ¨λ“œμ™€ μ—„κ²©ν•˜μ§€ μ•Šμ€ λͺ¨λ“œμ—μ„œμ˜ μ˜ˆμ•½μ–΄

enum μ‹λ³„μžλŠ” 일반적으둜 μ˜ˆμ•½λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.

var enum = { RED: 0, GREEN: 1, BLUE: 2 };
// SyntaxError: enum is a reserved identifier

엄격 λͺ¨λ“œμ˜ μ½”λ“œμ—μ„  더 λ§Žμ€ μ‹λ³„μžλ“€μ΄ μ˜ˆμ•½λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.

"use strict";
var package = ["potatoes", "rice", "fries"];
// SyntaxError: package is a reserved identifier

이 λ³€μˆ˜λ“€μ˜ 이름을 λ³€κ²½ν•΄μ•Ό ν•©λ‹ˆλ‹€.

var colorEnum = { RED: 0, GREEN: 1, BLUE: 2 };
var list = ["potatoes", "rice", "fries"];

였래된 λΈŒλΌμš°μ €μ˜ μ—…λ°μ΄νŠΈ

μƒˆλ‘œμš΄ ꡬ문을 μ‚¬μš©ν•˜κΈ° μœ„ν•΄μ„œλŠ” 졜근 λ²„μ „μ˜ λΈŒλΌμš°μ €λ‘œ μ—…λ°μ΄νŠΈ ν•΄μ•Ό ν•©λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, 였래된 λΈŒλΌμš°μ €λ₯Ό μ‚¬μš©ν•˜κ³  μžˆλ‹€λ©΄ let λ˜λŠ” class κ΅¬ν˜„ν•  수 μ—†μŠ΅λ‹ˆλ‹€.

"use strict";
class DocArchiver {}

// SyntaxError: class is a reserved identifier
// (였래된 λ²„μ „μ˜ λΈŒλΌμš°μ €μ—μ„œλ§Œ μ—λŸ¬κ°€ λ°œμƒν•©λ‹ˆλ‹€. 예) Firefox 44 μ΄ν•˜)

같이 보기