Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
Identifier has been declared

since I am a beginner can't know what is happening there. could you help/explain to me what is happening?

It works with all the properties except the "location", it says:

property has been declared

'use strict';

const restaurant = {
  name: 'Classico Italiano',
  location: 'Via Angelo Tavanti 23, Firence, Italy',
  categories: ['Italian', 'Pizzeria', 'Vegetarian', 'Organic'],
  starterMenu: ['Focaccia', 'Bruschetta', 'Garlic Bread', 'Caprese Salad'],
  mainMenu: ['Pizza', 'Pasta', 'Risotto'],
  hello_kitty: function (two, three) {
    return [this.starterMenu[two], this.mainMenu[three]];
  },
};


const {location} = restaurant;
console.log(location);

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

As your console tells: can't assign the location property into a new variable because it has been declared before.

this happened because your Javascript run in a environment (browser) and this environment has some variables and methods on it.

you can see this via:

console.log(window)

the result would be:

Window {0: global, window: Window, self: Window, document: document, name: '', location: Location, …}

as you see, location is a predefined property that exists in your window object, so declaring new location property in the global scope was the cause of the issue.

if you are familiar with the scopes in Javascript, you can simply wrap your code snippet into a function to make it work properly:

'use strict';

function logLocation(){
   const restaurant = {
      name: 'Classico Italiano',
      location: 'Via Angelo Tavanti 23, Firence, Italy',
      categories: ['Italian', 'Pizzeria', 'Vegetarian', 'Organic'],
      starterMenu: ['Focaccia', 'Bruschetta', 'Garlic Bread', 'Caprese Salad'],
      mainMenu: ['Pizza', 'Pasta', 'Risotto'],
      hello_kitty: function (two, three) {
        return [this.starterMenu[two], this.mainMenu[three]];
      },
  };


  const {location} = restaurant;
  console.log(location);
}

logLocation()

about 4 years ago · Juan Pablo Isaza Denunciar

0

If you are using this code in the browser's console it is natural to get this error as location is a reserved name for the Location Object, an object that contains information about the current page URL.

See : https://www.w3schools.com/jsref/obj_location.asp

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda