Type conversion
By now, we know that Solidity is a statically typed language, where variables are defined with specific data types at compile time. The data type cannot be changed for the lifetime of the variable. This means that it can only store values that are legal for a data type – for example, uint8 can store values from 0 to 255. It cannot store negative values or values greater than 255. Take a look at the following code to better understand this:
// SPDX-License-Identifier: MIT pragma solidity >=0.7.0 <0.9.0; contract ErrorDataType { function HoistingDemo() public pure returns (uint){ uint8 someVar = 100; someVar = 300; //error } }
However, there are times when these...