var vs let js
let: //only available inside the scope it's declared, like in "for" loop,
var: //accessed outside the loop "for"
var vs let js
let: //only available inside the scope it's declared, like in "for" loop,
var: //accessed outside the loop "for"
let in javascript
The let statement declares a block scope local variable, optionally initializing it to a value.
let x = 1;
if (x === 1) {
let x = 2;
console.log(x);
// expected output: 2
}
console.log(x);
// expected output: 1
let javascript
* Variables defined with let cannot be redeclared.
* You cannot accidentally redeclare a variable.
let x = "John Doe";
let x = 0;
// SyntaxError: 'x' has already been declared
let javascript
The let statement declares a block-scoped local variable,
optionally initializing it to a value.
let x=1;
let javascript
var i = "global";
function foo() {
var i = "local"; // Otra variable local solo para esta función
console.log(i); // local
}
foo();
console.log(i); // global
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us