Horje
js var Code Example
js var
var x = y, y = 'A';
console.log(x + y); // non definito
js var
var a = 'A';
var b = a;

// è come dire:

var a, b = a = 'A';
js var
var nomevariabile1 [= valore1] [, nomevariabile2 [= valore2] ... [, nomevariabileN [= valoreN]]];
js var
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!
js var
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
js var
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ù.
js var
console.log(a);                // Genera un ReferenceError.
console.log('still going...'); // Non verrà eseguito.
js var
var a = 0, b = 0;
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...".
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




Javascript

Related
how to call javascript function in p tag Code Example how to call javascript function in p tag Code Example
jquery set radio button checked Code Example jquery set radio button checked Code Example
set cookie and get cookie in javascript Code Example set cookie and get cookie in javascript Code Example
puppeteer open browser authentication facebook Code Example puppeteer open browser authentication facebook Code Example
swagger next js Code Example swagger next js Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8