• 카테고리

    질문 & 답변
  • 세부 분야

    웹 개발

  • 해결 여부

    미해결

ES6 문법 문제

22.04.20 15:41 작성 조회수 149

0

ES6 문법 문제 1번 문제를 replit으로 하니깐

let name="noona's fruit store" let fruits = ["banana","apple","mango"] let location="Seoul" let store = {name, fruits, location} console.log(store)

요렇게 하니

Identifier 'location' has already been declared. 에러가 납니다.  그래서 변수 선언을 let 에서 var로 바꾸고  locatin 을 var loca로 바꾸니깐 실행이 되었습니다.  왜 에러가 나는 걸까요? 

var name ="nonna's fruit store";

var fruits =["banana","apple","mango"];

var loca ="Seoul";

var store = {name, fruits, loca}

console.log(store)

 

 

답변 1

답변을 작성해보세요.

1

안녕하세요 

예전에도 같은 질문을 해주신 분이 계셨는데 

location이 이미 시스템에서 사용하고있는 예약어 입니다 

따라서 location이라는 변수명을 안써주시면 됩니다.

address나 다른 이름으로 바꾸시면 더 좋을것 같네요!