Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!