Skip to content
Advertisement

Proper variable name for find method [closed]

I’m Japanese web developer. I’m currently thinking about the proper variable name for the result from javascript find method. I would rather not use “result” because it is too simple and it’s hard to understand what’s inside. Does anyone have any idea?

const targetChar = 'someName1';

let arrayOfObj = [
  {
    name: 'someName1',
    age: 38
  },
  {
    name: 'someName2',
    age: 24
  }
];

const result = arrayOfObj.find((obj) => {
  return obj.name === targetChar;
});

console.log(result);

Advertisement

Answer

Any name that is in unicode is proper name so don’t worry. Maybe you can check out commonly used naming conventions for commonly used javascript libraries or go with foundPeople. But if you are going to use it for an if statement you can choose isFound or hasFound which is shorter and easier to read.

The context, in other words where you are going to use the variable is important when choosing names. If the variable is global, or if you are going to use the found item later, a more descriptive name could be more helpful but if you are merely checking if such a person exist, shorter ones like isFound, hasFound or isExist is better.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement