Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
why doesn't dot notation work in function parameter?

This code is simple it is used to get the scanned Items and return their value if the scannedItems aren't there then it will return undefined, but for some reason the dot notation doesn't work for my function but only the bracket notation! i want to know out of curiosity why isn't it working for dot notation with detailed explanation

The code with dot notation

let foods = {
  apples: 25,
  oranges: 32,
  plums: 28,
  bananas: 13,
  grapes: 35,
  strawberries: 27
};

function checkInventory(scannedItem) {

var inventory = foods.scannedItem;

return inventory;
  
}

console.log(checkInventory("apples"));
The code with Bracket Notation
let foods = {
  apples: 25,
  oranges: 32,
  plums: 28,
  bananas: 13,
  grapes: 35,
  strawberries: 27
};

function checkInventory(scannedItem) {

var inventory = foods[scannedItem];

return inventory;
  
}

console.log(checkInventory("apples"));

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What comes after the dot is the name of the key which means you must know the key in advance and that is a limitation. Likely we have bracket notation that take a string letral for key name or a variable that holds your requested key for the cases when key is provided by user for example or key is passed in function args in your case.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda