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)

์—๋Ÿฌ ํƒ€์ž…

SyntaxError

๋ฌด์—‡์ด ์ž˜๋ชป๋˜์—ˆ์„๊นŒ?

์˜ˆ์•ฝ์–ด๊ฐ€ ์‹๋ณ„์ž๋กœ ์“ฐ์ธ ๊ฒฝ์šฐ ๋ฐœ์ƒํ•˜๋Š” ์—๋Ÿฌ์ž…๋‹ˆ๋‹ค. ์ด ํ‚ค์›Œ๋“œ๋Š” ์—„๊ฒฉ(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 ์ดํ•˜)

๊ฐ™์ด ๋ณด๊ธฐ