The var
keyword is soft-deprecated, and should not be used to redeclare existing variables.
It is possible to re-declare the same variable using the var
keyword:
var a = 1;
var a = 10; // valid!
However, this can have unintentional side effects on the code:
var x = 10;
{
var x = 20;
}
console.log(x); // 20
var db = dbDriver.loadTables()
{
var db = db.get("usersId:1234") // bad practice!
}
// always use 'let' or 'const'
const db = dbDriver.loadTables();
{
const users = db.get("userId:1234") // avoid shadowing
}