hugojavadi
hugojavadi

Reputation: 25

What is the purpose of a parameter, with an underscore before it, that is not used inside the function?

I am reading an article about how somebody went about building a data table with React - https://engineering.shopify.com/blogs/engineering/building-data-table-component-react. The following method is on the DataTable component. What is the purpose of the _cell parameter? It is not used inside the method!

renderHeadingRow = (_cell, cellIndex) => {
    const { headings } = this.props;

    return (
        <Cell
            key={`heading-${cellIndex}`}
            content={headings[cellIndex]}
            header={true}
        />
    )
}

Upvotes: 2

Views: 1790

Answers (3)

Aabhushan Gautam
Aabhushan Gautam

Reputation: 228

_ Naming conventions are rarely used, and when used it is used to denote PRIVATE . Even though it cannot be really enforced by JavaScript, declaring something as private tells us about how it should be used or how it should not be used.

For instance, a private method in a class should only be used internally by the class, but should be avoided to be used on the instance of the class.

Read More Here : https://www.robinwieruch.de/javascript-naming-conventions

Upvotes: 0

Denny Johansson
Denny Johansson

Reputation: 41

It's just a standard to show that the argument is never used inside the function scope but you would need to have it to access the second argument.

Upvotes: 2

Gonzalo
Gonzalo

Reputation: 1876

The underscore is used in order the IDEs don't warn you about an unused parameter. So, if you need to access the second parameter of the function but you won't use the first one, you can add an underscore to prevent the warning of unused parameter.

Upvotes: 2

Related Questions