Var 2/3
Var Tolerate Redeclaration
Var tolerates the redeclaration. If a variable is declared with the same name twice with var we will not get an error, but with let we will get an error. For instance:
12let user = 'Mike'; let user = 'John';
But we can declare variables with the same names with var and the old values of the variables are simply overwritten, for example.
123var user = 'Mike'; var user = 'John'; console.log(user)
Swipe to start coding
Declare a variable company and assign the value " Apple". Redeclare the company and now set the value “Samsung” by using the var keyword. Show the updated value on the console.
Solução
Variable hoisting
Hoisting, in JavaScript, is a way where a function or a variable can be used before its declaration.
In JavaScript, var is hoisted while the let and const does not allow hoisting, for example.
123totalNumber = 10; console.log(totalNumber); var totalNumber;
If we use the variable inside console.log() and nothing is written before it we will get an undefined value. In JavaScript first, the memory is allocated to the variable and initially, their values are undefined after this they are assigned some values.
12console.log(company) var company="panasonic";
Obrigado pelo seu feedback!
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Incrível!
Completion taxa melhorada para 2
Var 2/3
Deslize para mostrar o menu
Var Tolerate Redeclaration
Var tolerates the redeclaration. If a variable is declared with the same name twice with var we will not get an error, but with let we will get an error. For instance:
12let user = 'Mike'; let user = 'John';
But we can declare variables with the same names with var and the old values of the variables are simply overwritten, for example.
123var user = 'Mike'; var user = 'John'; console.log(user)
Swipe to start coding
Declare a variable company and assign the value " Apple". Redeclare the company and now set the value “Samsung” by using the var keyword. Show the updated value on the console.
Solução
Variable hoisting
Hoisting, in JavaScript, is a way where a function or a variable can be used before its declaration.
In JavaScript, var is hoisted while the let and const does not allow hoisting, for example.
123totalNumber = 10; console.log(totalNumber); var totalNumber;
If we use the variable inside console.log() and nothing is written before it we will get an undefined value. In JavaScript first, the memory is allocated to the variable and initially, their values are undefined after this they are assigned some values.
12console.log(company) var company="panasonic";
Obrigado pelo seu feedback!
single