Why do some new programming languages have var

Why do some newer programming languages almost always have the var keyword and write the type after the variable, for example:

var x int = 12345
var y: Int = 67890

I know that type inference can be implemented in this way, which can be written as follows:

var x = 12345
var y = 67890

so that the compiler treats x as an int type, but can"t it be done without var? Isn"t it easier to read as follows:

int x = 123
int y = 456
// :
x = 123
y = 456
Can"t the compiler recognize x in x = 123 statements as int without var?
also ask the boss to solve the problem.


I'm just a semi-lame technology. Personally, I think it should be to open a new variable to apply for memory. You said to remove the var and use the type to represent the new variable. Grammar


that's OK. Python doesn't have to..


first. Conclusion: without var, the compiler / interpreter can also infer the type.
next var/const I personally understand is similar to syntax sugar, after all, for weak types (such as JS), the var let const keyword is also ES5,ES6 into the standard.

Menu