js var
var a;
console.log(a); // scrive in console "undefined" o "" a seconda del browser usato.
console.log('still going...'); // scrive in console "still going...".
4
10
var nomevariabile1 [= valore1] [, nomevariabile2 [= valore2] ... [, nomevariabileN [= valoreN]]];
Thank you!
10
0
3.86
7
console.log(a); // Genera un ReferenceError.
console.log('still going...'); // Non verrà eseguito.
Thank you!
7
0
3.5
4
var a = 1;
b = 2;
delete this.a; // Genera un TypeError in strict mode. Altrimenti fallisce senza generare messaggi.
delete this.b;
console.log(a, b); // Genera un ReferenceError.
// La proprietà 'b' è stata cancellata e non esiste più.
Thank you!
4
0
3.88
8
var a = 'A';
var b = a;
// è come dire:
var a, b = a = 'A';
Thank you!
8
0
3
1
function x() {
y = 1; // Genera un ReferenceError in strict mode
var z = 2;
}
x();
console.log(y); // scrive "1" in console
console.log(z); // Genera un ReferenceError: z non è definita fuori dalla funzione x
Thank you!
1
0
3.7
10
var x = y, y = 'A';
console.log(x + y); // non definito
Thank you!
10
0
4.5
2
var a = 0, b = 0;
Thank you!
2
0
4.33
6
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
Thank you!
6
0
3.86
7
var x = 0;
function f() {
var x = y = 1; // x è dichiarata localmente. y invece no!
}
f();
console.log(x, y); // Genera un ReferenceError in strict mode (y non è definita). 0, 1 altrimenti.
// In modalità non-strict mode:
// x è la globale come si ci aspettava
// però, y è uscita fuori dalla funzione!
Thank you!
7
0
Are there any code examples left?
New code examples in category Javascript
-
Javascript 2023-04-21 22:52:36
-
Javascript 2022-03-27 22:25:20 javascript download string as file
-
Javascript 2022-03-27 21:40:22 sort numbers in array javascript
-
Javascript 2022-03-27 21:20:04 compare two arrays and return the difference javascript
-
Javascript 2022-03-27 21:15:02 javascript regex french phone number
-
Javascript 2022-03-27 21:05:03 cypress custom error message
-
Javascript 2022-03-27 21:00:05 create element javascript with id
-
Javascript 2022-03-27 20:40:57 feather icons react
-
Javascript 2022-03-27 20:20:01 how to make graphql request in axios
-
Javascript 2022-03-27 20:15:07 bootstrap validator password and confirm password