What is the difference between leading and trailing underscore in variables in Solidity?

Variables with a leading underscore usually represent an internal variable. While those with a trailing underscore mean they are external.

Internal means the variable is used internally within the class or smart contract while external means it is used outside the contract such as accepting data from user input.

Below is an example of variables with underscore in front (leading) and at the back (trailing).


    string private _name;

    string private _symbol;

    constructor(string memory name_, string memory symbol_)
        public
    {
        _name = name_;
        _symbol = symbol_;
    }

The variables _name and _symbol are both internal or private. The external variables name_ and symbol_ are variables that work as the constructor function parameter.