variables in js
var Hello = "World";
let bool = false;
const int = 8788;
variables in js
var Hello = "World";
let bool = false;
const int = 8788;
js var
var x = 0; // x è dichiarata dentro l'ambiente file, poi le è assegnato valore 0
console.log(typeof z); // undefined, poichè z ancora non esiste
function a() { // quando a è chiamata,
var y = 2; // y è dichiarata dentro l'ambiente della funzione a, e le è assegnato valore 2
console.log(x, y); // 0 2
function b() { // quando b è chiamata
x = 3; // assegna 3 all'esistente ambiente x, non crea una nuova variabile globale
y = 4; // assegna 4 all'esistente esterna y, non crea una nuova variabile globale
z = 5; // crea una nuova variabile globale z e le assegna valore 5.
} // (Throws a ReferenceError in strict mode.)
b(); // chiamare b crea z come variabile globale
console.log(x, y, z); // 3 4 5
}
a(); // chiamando a si richiama b
console.log(x, z); // 3 5
console.log(typeof y); // non definito, perchè y è locale alla funzione a
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