let javascript
// var has function scope.
// let has block scope.
function func(){
if(true){
var A = 1;
let B = 2;
}
A++; // 2 --> ok, inside function scope
B++; // B is not defined --> not ok, outside of block scope
return A + B; // NaN --> B is not defined
}let: //only available inside the scope it's declared, like in "for" loop,
var: //accessed outside the loop "for"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: 1var i = "global";
function foo() {
var i = "local"; // Otra variable local solo para esta función
console.log(i); // local
}
foo();
console.log(i); // globallet /*Var name*/ = /*what is equals*/
Also in JavaScript:
- detect emoji in string javascript
- add jquery cdn
- vuex-module-decorators access other state
- html video tag autoplay not working
- pdf reader js library
- get if there is a value in an array node js
- node loop files and push to array to display on screen with nunjucks
- javascript modal
- splice method js
- ruby json delete key
- how to draw a triangle using javascript
- closure javascript mdn
- const in javascript
- Robux gift
- location.reload sweetalert
- fetch api react
- react native init specific version
- react post request
- TypeError [ERR_INVALID_ARG_TYPE]: The "from" argument must be of type string. Received undefined at validateString (internal/validators.js:120:11)
- jquery for element which doesnt exist on page load
- three js clock
- event module in node js
- react native run on device command line
- jquery label with text