diff options
author | Ryan Johnson <rjohnson@mozilla.com> | 2021-04-29 16:16:42 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-29 16:16:42 -0700 |
commit | 95aca4b4d8fa62815d4bd412fff1a364f842814a (patch) | |
tree | 5e57661720fe9058d5c7db637e764800b50f9060 /files/it/web/javascript/reference/statements | |
parent | ee3b1c87e3c8e72ca130943eed260ad642246581 (diff) | |
download | translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.tar.gz translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.tar.bz2 translated-content-95aca4b4d8fa62815d4bd412fff1a364f842814a.zip |
remove retired locales (#699)
Diffstat (limited to 'files/it/web/javascript/reference/statements')
11 files changed, 0 insertions, 2277 deletions
diff --git a/files/it/web/javascript/reference/statements/break/index.html b/files/it/web/javascript/reference/statements/break/index.html deleted file mode 100644 index 8799911ff9..0000000000 --- a/files/it/web/javascript/reference/statements/break/index.html +++ /dev/null @@ -1,130 +0,0 @@ ---- -title: break -slug: Web/JavaScript/Reference/Statements/break -translation_of: Web/JavaScript/Reference/Statements/break ---- -<div>{{jsSidebar("Statements")}}</div> - -<p>Lo <strong>statement break </strong>interrompe il loop corrente, termina uno statement {{jsxref("Statements/switch", "switch")}}, o trasferisce l'esecuzione verso un {{jsxref("Statements/label", "label")}} .</p> - -<div>{{EmbedInteractiveExample("pages/js/statement-break.html")}}</div> - - - -<h2 id="Sinstassi">Sinstassi</h2> - -<pre class="syntaxbox notranslate"><code>break [<em>label</em>];</code></pre> - -<dl> - <dt><code>label</code> {{optional_inline}}</dt> - <dd>Identificatore che può essere anche associato ad una {{jsxref("Statements/label", "label")}}. Se lo statement non è un loop o uno {{jsxref("Statements/switch", "switch")}}, il label è necessario.</dd> -</dl> - -<h2 id="Descrizione">Descrizione</h2> - -<p>Lo statement <code>break</code> può contenere un parametro opzionale ({{jsxref("Statements/label", "label")}}) che impone al programma di interrompere l'esecuzione e saltare ad un determinato punto nel programma, indicato dalla label stessa. La label può anche essere uno degli statement jsxref("Statements/block", "block")}}; e non dovrà essere preceduto da uno statement loop.<br> - Uno statement <code>break</code>, con o senza label opzionale, non può essere usato nel corpo di una funzione innestata in un loop o uno switch, poichè quando verrà eseguito <code>break</code> il programma verrà terminato insieme al loop o allo switch.</p> - -<h2 id="Esempi">Esempi</h2> - -<h3 id="break_in_un_while_loop">break in un while loop</h3> - -<p>La seguente funzione contiene uno statement <code>break</code> che interromperà il {{jsxref("Statements/while", "while")}} loop quando la variabile <code>i</code> avrà valore 3, quindi restituirà il valore di 3 * <code>x</code>.</p> - -<pre class="brush:js;highlight:[6]; notranslate">function testBreak(x) { - var i = 0; - - while (i < 6) { - if (i == 3) { - break; - } - i += 1; - } - - return i * x; -}</pre> - -<h3 id="break_in_labeled_blocks">break in labeled blocks</h3> - -<p>Il seguente codice usa lo statement <code>break</code> con un blocco definito da una {{jsxref("Statements/label", "label")}}. Lo stetement <code>break</code> deve essere innestato all'interno di qualsiasi label a cui fa riferimento. Nota che <code>inner_block</code> è innestato dentro <code>outer_block</code>.</p> - -<pre class="brush:js;highlight:[1,2,4]; notranslate">outer_block: { - inner_block: { - console.log('1'); - break outer_block; // esce sia da inner_block che da outer_block - console.log(':-('); // non viene eseguito - } - console.log('2'); // non viene eseguito -} -</pre> - -<h3 id="break_in_labeled_blocks_che_genera_un_errore">break in labeled blocks che genera un errore</h3> - -<p>Il codice seguente usa lo statement <code>break</code> nei labeled block, ma genera un <code>SyntaxError</code> poichè il <code>break</code> è all'interno del <code>block_1</code> ma fa riferimento a <code>block_2</code>. Uno statement <code>break</code> deve sempre essere innestato all'interno dei blocchi a cui si riferiscono i {{jsxref("Statements/label", "label")}}.</p> - -<pre class="brush:js;highlight:[1,3,6]; notranslate">block_1: { - console.log('1'); - break block_2; // SyntaxError: label not found -} - -block_2: { - console.log('2'); -} -</pre> - -<h3 id="break_allinterno_di_funzioni">break all'interno di funzioni</h3> - -<p>Verranno generati <code>SyntaxError</code> anche nei seguenti esempi di codice dove viene usato lo stetement <code>break</code> all'interno di funzioni che sono innestate nei cicli loop, oppure all'interno di funzioni innestate in labeled block, per cui lo stetemen <code>break</code> si intende come stop all'esecuzione e uscita.</p> - -<pre class="brush:js;highlight:[1,3,6]; notranslate">function testBreak(x) { - var i = 0; - - while (i < 6) { - if (i == 3) { - (function() { - break; - })(); - } - i += 1; - } - -return i * x; -} - -testBreak(1); // SyntaxError: Illegal break statement -</pre> - -<pre class="brush:js;highlight:[1,3,6]; notranslate">block_1: { - console.log('1'); - ( function() { - break block_1; // SyntaxError: Undefined label 'block_1' - })(); -} -</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specifiche</th> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-break-statement', 'Break statement')}}</td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_dei_Browser">Compatibilità dei Browser</h2> - - - -<p>{{Compat("javascript.statements.break")}}</p> - -<h2 id="Vedi_anche">Vedi anche</h2> - -<ul> - <li>{{jsxref("Statements/continue", "continue")}}</li> - <li>{{jsxref("Statements/label", "label")}}</li> - <li>{{jsxref("Statements/switch", "switch")}}</li> -</ul> diff --git a/files/it/web/javascript/reference/statements/empty/index.html b/files/it/web/javascript/reference/statements/empty/index.html deleted file mode 100644 index bb10fd7165..0000000000 --- a/files/it/web/javascript/reference/statements/empty/index.html +++ /dev/null @@ -1,102 +0,0 @@ ---- -title: empty -slug: Web/JavaScript/Reference/Statements/Empty -translation_of: Web/JavaScript/Reference/Statements/Empty ---- -<div>{{jsSidebar("Statements")}}</div> - -<p>Un <strong>empty statement</strong> (istruzione vuota) è utilizzato per evitare di inserire uno statement nel caso in cui la sintassi JavaScript ne richieda uno.</p> - -<div>{{EmbedInteractiveExample("pages/js/statement-empty.html")}}</div> - -<p class="hidden">Il sorgente per questo esempio interattivo è immagazzinato in un repository GitHub. Se vuoi contribuire al progeeto degli esempi interattivi, clona <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> e inviaci una pull request.</p> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox">; -</pre> - -<h2 id="Descrizione">Descrizione</h2> - -<p>L'empty statement è un punto e virgola (;) che indica che nessuno statement sarà eseguito, nonostante la sintassi JavaScript ne richieda uno. Il comportamento opposto, quando vuoi eseguire più statement ma JavaScript ne consente uno solo, è reso possibile dall'utilizzo di un<a href="/en-US/docs/Web/JavaScript/Reference/Statements/block"> block statement</a>; esso ne combina diversi in un singolo statement .</p> - -<h2 id="Esempi">Esempi</h2> - -<p>L'empty statement è utilizzato talvolta con i loop statements. Guarda l'esempio seguente con un copro del loop vuoto:</p> - -<pre class="brush: js">var arr = [1, 2, 3]; - -// Assegna il valore 0 a tutti gli elementi dell'array -for (i = 0; i < arr.length; arr[i++] = 0) /* empty statement */ ; - -console.log(arr) -// [0, 0, 0] -</pre> - -<p><strong>Nota:</strong> E' una buona pratica commentare l'utilizzo intenzionale di empty statement, poichè non è immediatamente ovvia la differenza con un normale punto e virgola. Nell'esempio seguente l'uso è probabilmente non intenzionale:</p> - -<pre class="brush: js">if (condition); // Attenzione, questo "if" non produce nessun effetto! - killTheUniverse() // E quindi questo sarà eseguito sempre!!! -</pre> - -<p>Un altro Esempio: Un <a href="/en-US/docs/Web/JavaScript/Reference/Statements/if...else"><code>if...else</code></a> statement senza parentesi graffe (<code>{}</code>). Se <code>three</code> è <code>true</code>, non accadrà nulla, <code>four</code> non viene valutato, e neanche la funzione <code>launchRocket()</code>nel ramo <code>else</code> sarà eseguita.</p> - -<pre class="brush: js">if (one) - doOne(); -else if (two) - doTwo(); -else if (three) - ; // nothing here -else if (four) - doFour(); -else - launchRocket();</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specification</th> - <th scope="col">Status</th> - <th scope="col">Comment</th> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-empty-statement', 'Empty statement')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-empty-statement', 'Empty statement')}}</td> - <td>{{Spec2('ES6')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-12.3', 'Empty statement')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ES3', '#sec-12.3', 'Empty statement')}}</td> - <td>{{Spec2('ES3')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ES1', '#sec-12.3', 'Empty statement')}}</td> - <td>{{Spec2('ES1')}}</td> - <td>Initial definition.</td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_con_i_Browser">Compatibilità con i Browser</h2> - - - -<p>{{Compat("javascript.statements.empty")}}</p> - -<h2 id="See_also">See also</h2> - -<ul> - <li>{{jsxref("Statements/block", "Block statement")}}</li> -</ul> diff --git a/files/it/web/javascript/reference/statements/export/index.html b/files/it/web/javascript/reference/statements/export/index.html deleted file mode 100644 index 47d67a6eb2..0000000000 --- a/files/it/web/javascript/reference/statements/export/index.html +++ /dev/null @@ -1,259 +0,0 @@ ---- -title: export -slug: Web/JavaScript/Reference/Statements/export -tags: - - ECMAScript 2015 - - JavaScript - - Moduli - - export -translation_of: Web/JavaScript/Reference/Statements/export ---- -<div>{{jsSidebar("Statements")}}</div> - -<div>Il comando <strong>export </strong>è utilizzato per esportare funzioni, oggetti o tipi primitivi da un dato file (o modulo) in modo tale da poter essere riutilizzati in altri file con il comando <span class="seoSummary">{{jsxref("Statements/import", "import")}}</span></div> - -<div></div> - -<div>I moduli sono esportati sempre in {{jsxref("Strict_mode","strict mode", "", 1)}} nonostante non sia dichiarato. Il comando export non può essere usato in embedded scripts.</div> - -<h2 id="Sintassi">Sintassi</h2> - -<p>Ci sono due tipi di exports:</p> - -<ol> - <li>Named exports (uno o più exports per modulo)</li> - <li>Default exports (uno per modulo)</li> -</ol> - -<pre class="syntaxbox notranslate">// Export di variabili, funzioni e oggetti singolarmente -export let <var>name1</var>, <var>name2</var>, …, <var>nameN</var>; // also var, const -export let <var>name1</var> = …, <var>name2</var> = …, …, <var>nameN</var>; // also var, const -export function functionName(){...} -export class ClassName {...} - -// Export di una lista -export { <var>name1</var>, <var>name2</var>, …, <var>nameN</var> }; - -// Rinominare gli exports -export { <var>variable1</var> as <var>name1</var>, <var>variable2</var> as <var>name2</var>, …, <var>nameN</var> }; - -// Exporting destructured assignments with renaming -// Export di assegnazioni destrutturate rinominando l'export -export const { <var>name1</var>, <var>name2: bar</var> } = o; - -// DEfault export -export default <em>expression</em>; -export default function (…) { … } // also class, function* -export default function name1(…) { … } // also class, function* -export { <var>name1</var> as default, … }; - -// Aggregazione di moduli -export * from …; // does not set the default export -export * as name1 from …; // Draft ECMAScript® 2O21 -export { <var>name1</var>, <var>name2</var>, …, <var>nameN</var> } from …; -export { <var>import1</var> as <var>name1</var>, <var>import2</var> as <var>name2</var>, …, <var>nameN</var> } from …; -export { default } from …;</pre> - -<dl> - <dt><code>nameN</code></dt> - <dd>Nome che deve essere esportato (così da poter essere importato via <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/import">import</a></code> in un altro script).</dd> -</dl> - -<h2 id="Descrizione">Descrizione</h2> - -<p>Ci sono due tipi diversi di export, named and default. Puoi avere più named exports per modulo ma solamente un default export.</p> - -<p>Named exports:</p> - -<pre class="brush: js notranslate">// Export di variabili, funzioni, oggetti dichiarati precedentemente -export { myFunction, myVariable }; - -// export individual features (can export var, let, -// const, function, class) -export let myVariable = Math.sqrt(2); -export function myFunction() { ... };</pre> - -<p>Default exports:</p> - -<pre class="brush: js notranslate">// Export di funzioni dichiarati precedentemente come default -export { myFunction as default }; - -// Export di singole funzioni, oggetti come default -export default function () { ... } -export default class { .. } - -// ogni export sovrascrive il precedente</pre> - -<p>I named exports sono utili per esportare più valori. Durante l'import, è obbligatorio usare lo stesso nome dell'oggetto corrispondente.</p> - -<p>I defalt export invece possono essere importati con qualsiasi nome. Ad esempio:</p> - -<pre class="brush: js notranslate">// file test.js -let k; export default k = 12; -</pre> - -<pre class="brush: js notranslate">// some other file -import m from './test'; //notare che abbiamo la libertà di importare m invece di importate k, perché k era il default export -console.log(m); // stamperà 12 -</pre> - -<p>Puoi anche rinominare i named exports per evitare conflitti:</p> - -<pre class="brush: js notranslate">export { <var>myFunction</var> as <var>function1</var>,<var> - myVariable</var> as variable };</pre> - -<h3 id="Ri-esportare_Aggregare">Ri-esportare / Aggregare</h3> - -<p>È anche possibile importare ed esportare da più moduli nel modulo padre in modo tale da rendere rendere disponibili gli import da quel modulo. In altre parole è possibile creare un modulo che aggreghi i vari export da vari moduli.</p> - -<p>È possibile farlo con la sintassi "export from":</p> - -<pre class="brush: js notranslate">export { default as function1, - function2 } from 'bar.js'; -</pre> - -<p>che è paragonabile ad una combinazione di import e export:</p> - -<pre class="brush: js notranslate">import { default as function1, - function2 } from 'bar.js'; -export { function1, function2 };</pre> - -<p>dove <code>function1</code> e <code>function2</code> non sono disponibili nel modulo corrente.</p> - -<div class="blockIndicator note"> -<p><strong>Note:</strong> I seguenti esempi sono sintatticamente invalidi nonostante siano equivalenti dal punto divista del comando import</p> -</div> - -<pre class="brush: js notranslate">import DefaultExport from 'bar.js'; // Valid</pre> - -<pre class="brush: js notranslate">export DefaultExport from 'bar.js'; // Invalid</pre> - -<p>Il modo corretto di farlo è di rinominare gli export:</p> - -<pre class="brush: js notranslate">export { default as DefaultExport } from 'bar.js';</pre> - -<h2 id="Esempi">Esempi</h2> - -<h3 id="Usare_gli_export_espliciti">Usare gli export espliciti</h3> - -<p>In un modulo <code>my-module.js</code>, potremmo includere il seguente codice:</p> - -<pre class="brush: js notranslate">// modulo "my-module.js" -function cube(x) { - return x * x * x; -} - -const foo = Math.PI + Math.SQRT2; - -var graph = { - options: { - color:'white', - thickness:'2px' - }, - draw: function() { - console.log('From graph draw function'); - } -} - -export { cube, foo, graph };</pre> - -<p>E nel modulo principale incluso nella pagina HTML potremmo avere</p> - -<pre class="brush: js notranslate">import { cube, foo, graph } from './my-module.js'; - -graph.options = { - color:'blue', - thickness:'3px' -}; - -graph.draw(); -console.log(cube(3)); // 27 -console.log(foo); // 4.555806215962888</pre> - -<p>Notare che:</p> - -<ul> - <li>È necessario includere questo script nella tua pagina HTML con un elemento {{htmlelement("script")}} di type="module", in modo tale che sia riconosciuta come modulo e gestita in modo appropriato</li> - <li>Non è possibile eseguire moduli JS visitando url <code>file://</code> perché riceveresti un errore per violazione delle regole <a href="https://wiki.developer.mozilla.org/en-US/docs/Web/HTTP/CORS">CORS</a>. È necessario eseguire questi script tramite un server HTTP</li> -</ul> - -<h3 id="Usare_i_default_export">Usare i default export</h3> - -<p>Se vogliamo esportare un singolo valore o avere un valore di default per il tuo modulo, allora possiamo usare il default export:</p> - -<pre class="brush: js notranslate">// modulo "my-module.js" -export default function cube(x) { - return x * x * x; -} -</pre> - -<p>Quindi, in un altro script, puoi importare il modulo direttamente:</p> - -<pre class="brush: js notranslate">import cube from 'my-module'; -console.log(cube(3)); // 27 -</pre> - -<h3 id="Usare_export_from">Usare export from</h3> - -<p>Facciamo l'esempio dove abbiamo i seguenti moduli:</p> - -<ul> - <li><code>childModule1.js</code>: exporta <code>myFunction</code> e <code>myVariable</code></li> - <li><code>childModule2.js</code>: esporta <code>myClass</code></li> - <li><code>parentModule.js</code>: è nient'altro che l'aggregatore</li> - <li>top level module: utilizza gli export di <code>parentModule.js</code></li> -</ul> - -<p>Questo è come sarebbe con il codice:</p> - -<pre class="brush: js notranslate">// Nel modulo childModule1.js -let myFunction = ...; // assegna una funzione myFunction -let myVariable = ...; // assegna un valore alla variabile myVariable -export {myFunction, myVariable}; -</pre> - -<pre class="brush: js notranslate">// Nel modulo childModule2.js -let myClass = ...; // assegna qualcosa di utile a myClass -export myClass; -</pre> - -<pre class="brush: js notranslate">// Nel modulo parentModule.js -// Aggreghiamo solamente gli export dai moduli childModule1 e childModule2 -// per poi riesportarli -export { myFunction, myVariable } from 'childModule1.js'; -export { myClass } from 'childModule2.js'; -</pre> - -<pre class="brush: js notranslate">// Nel modulo principale -// Possiamo usare gli export importandoli da un singolo modulo -// che li colleziona/include in un singolo modulo -import { myFunction, myVariable, myClass } from 'parentModule.js'</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">Specifiche</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('ESDraft', '#sec-exports', 'Exports')}}</td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_Browser">Compatibilità Browser</h2> - -<p>{{Compat("javascript.statements.export")}}</p> - -<h2 id="Vedi_anche">Vedi anche</h2> - -<ul> - <li>{{jsxref("Statements/import", "import")}}</li> - <li><a href="https://wiki.developer.mozilla.org/it/docs/Web/JavaScript/Guide/Modules">JavaScript modules</a> guide</li> - <li><a href="https://hacks.mozilla.org/2015/08/es6-in-depth-modules/">ES6 in Depth: Modules</a>, Hacks blog post by Jason Orendorff</li> - <li><a href="https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/">ES modules: A cartoon deep-dive</a>, Hacks blog post by Lin Clark</li> - <li><a href="http://exploringjs.com/es6/ch_modules.html">Axel Rauschmayer's book: "Exploring JS: Modules"</a></li> -</ul> diff --git a/files/it/web/javascript/reference/statements/for...of/index.html b/files/it/web/javascript/reference/statements/for...of/index.html deleted file mode 100644 index ffc6f472c0..0000000000 --- a/files/it/web/javascript/reference/statements/for...of/index.html +++ /dev/null @@ -1,264 +0,0 @@ ---- -title: for...of -slug: Web/JavaScript/Reference/Statements/for...of -translation_of: Web/JavaScript/Reference/Statements/for...of ---- -<p>{{jsSidebar("Statements")}}</p> - -<p><code><font face="Open Sans, Arial, sans-serif">Il </font><strong>costrutto for...of</strong></code> crea un ciclo con gli <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterable">oggetti iterabil</a>i (inclusi {{jsxref("Array")}}, {{jsxref("Map")}}, {{jsxref("Set")}}, {{jsxref("String")}}, {{jsxref("TypedArray")}}, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments">argomenti</a> di oggetti e così via), iterando le istruzioni per ogni valore di ogni proprietà.</p> - -<h2 id="Sintassi">Sintassi</h2> - -<pre>for (<em>variabile</em> of <em>oggettoIterabile</em>) { - <em>istruzioni -</em>} -</pre> - -<dl> - <dt><code>variabile</code></dt> - <dd><br> - Questa variabile assume il valore di una proprietà in ogni ciclo.</dd> - <dt><code>oggettoIterabile</code></dt> - <dd>Oggetto le cui proprietà sono iterate.</dd> -</dl> - -<h2 id="Esempi">Esempi</h2> - -<h3 id="Iterare_un_jsxref(Array)">Iterare un {{jsxref("Array")}}:</h3> - -<pre>let array = [10, 20, 30]; - -for (let valore of array) { - console.log(valore); -} -// Output: -// 10 -// 20 -// 30 -</pre> - -<p><code>Si può utilizzare <a href="/en-US/docs/Web/JavaScript/Reference/Statements/const">const</a></code> anzichè <a href="/en-US/docs/Web/JavaScript/Reference/Statements/let"><code>let</code></a> se 'value' non cambia valore durante il ciclo.</p> - -<pre>let iterable = [10, 20, 30]; - -for (const value of iterable) { - console.log(value); // il valore di value di questo ciclo rimarrà costante - value++; // operazione non consentita. -} -// 10 -// 20 -// 30 -</pre> - -<h3 id="Iterare_un_oggetto_jsxref(String)">Iterare un oggetto {{jsxref("String")}}:</h3> - -<pre>let iterable = "boo"; - -for (let value of iterable) { - console.log(value); -} -// output: -// "b" -// "o" -// "o" -</pre> - -<h3 id="Iterare_un_oggetto_jsxref(TypedArray)">Iterare un oggetto {{jsxref("TypedArray")}}:</h3> - -<pre>let iterable = new Uint8Array([0x00, 0xff]); - -for (let value of iterable) { - console.log(value); -} -// 0 -// 255 -</pre> - -<h3 id="Iterare_un_oggetto_jsxref(Map)">Iterare un oggetto {{jsxref("Map")}}:</h3> - -<pre>let iterable = new Map([["a", 1], ["b", 2], ["c", 3]]); - -for (let entry of iterable) { - console.log(entry); -} -// [a, 1] -// [b, 2] -// [c, 3] - -for (let [key, value] of iterable) { - console.log(value); -} -// 1 -// 2 -// 3 -</pre> - -<h3 id="Iterare_un_oggetto_jsxref(Set)">Iterare un oggetto {{jsxref("Set")}}:</h3> - -<pre>let iterable = new Set([1, 1, 2, 2, 3, 3]); - -for (let value of iterable) { - console.log(value); -} -// 1 -// 2 -// 3 -</pre> - -<h3 id="Iterare_un_DOM_collection">Iterare un DOM collection</h3> - -<div> -<p>Iterare un DOM collection come {{domxref("NodeList")}}: il seguente esempio aggiunge una classe 'read' ai paragrafi che sono discendenti diretti di un elemento <em>article</em>:</p> -</div> - -<div class="warning"> -<p>Nota: Questo costrutto funziona soltanto con le piattaforme che implementano NodeList.prototype[Symbol.iterator]</p> -</div> - -<div> -<pre>let articleParagraphs = document.querySelectorAll("article > p"); - -for (let paragraph of articleParagraphs) { - paragraph.classList.add("read"); -} -</pre> -</div> - -<h3 id="Iterare_generatori">Iterare generatori</h3> - -<p>Si possono iterare i <a href="/en-US/docs/Web/JavaScript/Reference/Statements/function*">generatori</a>:</p> - -<pre>function* fibonacci() { // generatore di funzione - let [prev, curr] = [0, 1]; - while (true) { - [prev, curr] = [curr, prev + curr]; - yield curr; - } -} - -for (let n of fibonacci()) { - console.log(n); - // tronca la sequenza a 1000 - if (n >= 1000) { - break; - } -} -</pre> - -<h3 id="Differerenze_tra_for...of_e_for...in">Differerenze tra <code>for...of</code> e <code>for...in</code></h3> - -<p>Il <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...in" title="en-US/docs/JavaScript/Reference/Statements/for...in">for...in</a></code> itera tutte le proprietà enumerabili di un oggetto.</p> - -<p>Il <code>for...of</code> è specifico per le <strong>collezioni</strong>, piuttosto che tutti gli oggetti. Itera tutti gli oggetti di qualsiasi collection che abbia la proprietà <code>[Symbol.iterator]</code>.</p> - -<p>Il seguente esempio mostra le differenze tra <code>for...of</code> e <code>for...in</code>.</p> - -<pre>Object.prototype.objCustom = function () {}; -Array.prototype.arrCustom = function () {}; - -let iterable = [3, 5, 7]; -iterable.foo = "hello"; - -for (let i in iterable) { - console.log(i); // logs 0, 1, 2, "foo", "arrCustom", "objCustom" -} - -for (let i of iterable) { - console.log(i); // logs 3, 5, 7 -} -</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table> - <tbody> - <tr> - <th scope="col">Specifica</th> - <th scope="col">Stato</th> - <th scope="col">Commenti</th> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-for-in-and-for-of-statements', 'for...of statement')}}</td> - <td>{{Spec2('ES6')}}</td> - <td>Definizione iniziale.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-for-in-and-for-of-statements', 'for...of statement')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_con_i_browser">Compatibilità con i browser</h2> - -<p>{{CompatibilityTable}}</p> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Edge</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatChrome(38)}} <a href="#Chrome_note_1">[1]</a><br> - {{CompatChrome(51)}} <a href="#Chrome_note_3">[3]</a></td> - <td>{{CompatGeckoDesktop("13")}} <a href="#Gecko_note_2">[2]</a></td> - <td>12</td> - <td>25</td> - <td>7.1</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Android</th> - <th>Chrome for Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatChrome(38)}} [1]</td> - <td>{{CompatGeckoMobile("13")}} [2]</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>8</td> - </tr> - </tbody> -</table> -</div> - -<p><a name="Chrome_note_1">[1]</a> Da Chrome 29 a Chrome 37 questa caratteristica era disponibile nel menu preferenze. In chrome://flags/#enable-javascript-harmony, bisognava attivare “Enable Experimental JavaScript”.</p> - -<p><a name="Gecko_note_2">[2]</a> Da Gecko 17 (Firefox 17 / Thunderbird 17 / SeaMonkey 2.14) a Gecko 26 (Firefox 26 / Thunderbird 26 / SeaMonkey 2.23 / Firefox OS 1.2) la proprietà iterator era usata (<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=907077">bug 907077</a>), e da Gecko 27 a Gecko 35 era utilizzato <code>"@@iterator"</code> placeholder. In Gecko 36 (Firefox 36 / Thunderbird 36 / SeaMonkey 2.33), il simbolo <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol">symbolo</a> <code>@@iterator</code> fu implementato (<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=918828">bug 918828</a>).</p> - -<p><a name="Chrome_note_3">[3]</a> Il supporto dell'iteration of objects è stato aggiunto in Chrome 51.</p> - -<h2 id="Note">Note</h2> - -<p>Se alcuni collegamenti su questa pagina fossero segnati in rosso e si volesse visualizzarli, essi sono dispoiìnibili solo in lingua inglese. In tal caso basta cambiare la lingua di questo stesso articolo.</p> - -<h2 id="See_also">See also</h2> - -<ul> - <li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for_each...in">for each...in</a> - a similar statement, but iterates over the values of object's properties, rather than the property names themselves (deprecated).</li> - <li>{{jsxref("Array.prototype.forEach()")}}</li> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach">Map.prototype.forEach()</a></li> -</ul> - -<p> </p> diff --git a/files/it/web/javascript/reference/statements/function_star_/index.html b/files/it/web/javascript/reference/statements/function_star_/index.html deleted file mode 100644 index a71ccfc55e..0000000000 --- a/files/it/web/javascript/reference/statements/function_star_/index.html +++ /dev/null @@ -1,280 +0,0 @@ ---- -title: function* -slug: Web/JavaScript/Reference/Statements/function* -translation_of: Web/JavaScript/Reference/Statements/function* ---- -<div>{{jsSidebar("Statements")}}</div> - -<p>La dichiarazione <code><strong>function*</strong></code> (la parola chiave <code>function</code> seguita da un asterisco) definisce una <em>funzione generatrice</em>, la quale restituisce un oggetto di tipo {{jsxref("Global_Objects/Generator","Generator")}}.</p> - -<p>{{EmbedInteractiveExample("pages/js/statement-functionasterisk.html")}}</p> - -<div class="noinclude"> -<p>È anche possibile definire una funzione generatrice usando il costrutto {{jsxref("GeneratorFunction")}} e una {{jsxref("Operators/function*", "espressione function*")}}.</p> -</div> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox">function* <em>nome</em>([<em>param</em>[, <em>param</em>[, ... <em>param</em>]]]) { - <em>istruzioni</em> -} -</pre> - -<dl> - <dt><code>nome</code></dt> - <dd>Il nome della funzione.</dd> -</dl> - -<dl> - <dt><code>param</code></dt> - <dd>Gli argomenti passati alla funzione. Una funzione può avere fino a 255 argomenti.</dd> -</dl> - -<dl> - <dt><code>istruzioni</code></dt> - <dd>Le istruzioni che compongono il corpo della funzione.</dd> -</dl> - -<h2 id="Descrizione">Descrizione</h2> - -<p>I generatori sono funzioni dalle quali è possibile uscire e poi rientrarvi in un secondo momento. Il loro contesto (binding delle variabili) verrà salvato all'uscita per quando vi entrerà successivamente.</p> - -<p>La chiamata ad un generatore non viene eseguita immediatamente; la funzione ritornerà invece un oggetto <a href="/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterator">iterator</a>. Quando il metodo <code>next()</code> dell'iteratore viene chiamato, il corpo del generatore viene eseguito fino alla prima espressione {{jsxref("Operators/yield", "yield")}}, la quale specifica quale espressione ritornare dall'iteratore oppure, con l'espressione {{jsxref("Operators/yield*", "yield*")}}, delegare questo valore ad un'altra funzione generatrice. Il metodo <code>next()</code> restituisce un oggetto con proprietà <code>value</code> contenente il valore da restituito all'iteratore ed una proprietà <code>done</code> che contiene un valore di tipo boolean per indicare se il generatore ha restituito l'ultimo valore. Chiamando il metodo <code>next()</code> con un argomento farà riprendere l'esecuzione della funzione generatrice, sostituendo l'istruzione <code>yield</code> in cui l'esecuzione era stata fermata con l'argomento della funzione <code>next()</code>. </p> - -<h2 id="Esempi">Esempi</h2> - -<h3 id="Esempio_semplice">Esempio semplice</h3> - -<pre class="brush: js">function* idMaker(){ - var index = 0; - while(index < 3) - yield index++; -} - -var gen = idMaker(); - -console.log(gen.next().value); // 0 -console.log(gen.next().value); // 1 -console.log(gen.next().value); // 2 -console.log(gen.next().value); // undefined -// ...</pre> - -<h3 id="Esempio_con_yield*">Esempio con yield*</h3> - -<pre class="brush: js">function* anotherGenerator(i) { - yield i + 1; - yield i + 2; - yield i + 3; -} - -function* generator(i){ - yield i; - yield* anotherGenerator(i); - yield i + 10; -} - -var gen = generator(10); - -console.log(gen.next().value); // 10 -console.log(gen.next().value); // 11 -console.log(gen.next().value); // 12 -console.log(gen.next().value); // 13 -console.log(gen.next().value); // 20 -</pre> - -<h3 id="Passare_argomenti_ai_Generatori">Passare argomenti ai Generatori</h3> - -<pre class="brush: js">function* logGenerator() { - console.log(yield); - console.log(yield); - console.log(yield); -} - -var gen = logGenerator(); - -// the first call of next executes from the start of the function -// until the first yield statement -gen.next(); -gen.next('pretzel'); // pretzel -gen.next('california'); // california -gen.next('mayonnaise'); // mayonnaise -</pre> - -<h3 id="I_generatori_non_sono_costruttori">I generatori non sono costruttori</h3> - -<pre class="brush: js example-bad">function* f() {} -var obj = new f; // solleva "TypeError: f is not a constructor"</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">Specifica</th> - <th scope="col">Stato</th> - <th scope="col">Commenti</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('ES6', '#', 'function*')}}</td> - <td>{{Spec2('ES6')}}</td> - <td>Definizione iniziale</td> - </tr> - <tr> - <td>{{SpecName('ES7', '#', 'function*')}}</td> - <td>{{Spec2('ES7')}}</td> - <td>I generatori non devono avere essere usati come costruttori e deveo lanciare un eccezione quando vengono usati con la parola chiave <code>new</code>.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#', 'function*')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_per_i_browser">Compatibilità per i browser</h2> - -<div>{{CompatibilityTable}}</div> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th> Edge</th> - <th>Opera</th> - <th>Safari (WebKit)</th> - </tr> - <tr> - <td>Supporto base</td> - <td>{{CompatChrome(39.0)}}</td> - <td>{{CompatGeckoDesktop("26.0")}}</td> - <td>{{CompatNo}}</td> - <td>13</td> - <td>26</td> - <td>{{CompatNo}}</td> - </tr> - <tr> - <td><code>yield*</code></td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoDesktop("27.0")}}</td> - <td>{{CompatNo}}</td> - <td>13</td> - <td>26</td> - <td>{{CompatNo}}</td> - </tr> - <tr> - <td><code>IteratorResult</code> invece delle eccezioni</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoDesktop("29.0")}}</td> - <td>{{CompatNo}}</td> - <td>13</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatNo}}</td> - </tr> - <tr> - <td>Non istanziabile con <code>new</code> {ES2016)</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoDesktop("43.0")}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Android</th> - <th>Android Webview</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - <th>Chrome for Android</th> - </tr> - <tr> - <td>Supporto base</td> - <td>{{CompatNo}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoMobile("26.0")}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatChrome(39.0)}}</td> - </tr> - <tr> - <td><code>yield*</code></td> - <td>{{CompatNo}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatGeckoMobile("27.0")}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - <tr> - <td><code>IteratorResult</code> invece delle eccezioni</td> - <td>{{CompatNo}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatGeckoMobile("29.0")}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatNo}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - <tr> - <td>Non istanziabile con <code>new</code> (ES2016)</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatGeckoMobile("43.0")}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - <td>{{CompatUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="Note_specifiche_per_Firefox">Note specifiche per Firefox</h2> - -<h4 id="Generatori_e_iteratori_in_Firefox_nelle_versioni_precedenti_alla_26">Generatori e iteratori in Firefox nelle versioni precedenti alla 26</h4> - -<p>Versioni di FIrefox precedenti implementano una versione più vecchia della proposta di standard per i generatori. Tra le varie differenze, in queste versioni i generatori erano definiti usando la parola chiave <code>function</code> (senza asterisco) per le funzioni semplici. Per maggiori informazioni fare riferimento a {{jsxref("Statements/Legacy_generator_function", "funzioni generatrici (legacy)")}}.</p> - -<h4 id="IteratorResult_al_posto_delle_eccezioni"><code>IteratorResult</code> al posto delle eccezioni</h4> - -<p>A partire da Gecko 29 {{geckoRelease(29)}}, la funzione generatrice completata non solleva più eccezioni {{jsxref("TypeError")}} "generator has already finished". Restituisce invece oggetti di tipo <code>IteratorResult</code> come il seguente <code>{ value: undefined, done: true }</code> ({{bug(958951)}}).</p> - -<h2 id="Vedi_anche">Vedi anche</h2> - -<ul> - <li>{{jsxref("Operators/function*", "Espressione function*")}}</li> - <li>Oggetto {{jsxref("GeneratorFunction")}}</li> - <li><a href="/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol">The Iterator protocol</a></li> - <li>{{jsxref("Operators/yield", "yield")}}</li> - <li>{{jsxref("Operators/yield*", "yield*")}}</li> - <li>Oggetto {{jsxref("Function")}}</li> - <li>{{jsxref("Statements/function", "dichiarazione di funzioni")}}</li> - <li>{{jsxref("Operators/function", "espressione function")}}</li> - <li>{{jsxref("Functions_and_function_scope", "Funzioni e scope di funzioni")}}</li> - <li>Altre risorse sul web: - <ul> - <li><a href="http://facebook.github.io/regenerator/">Regenerator</a> un compilatore di generatori da ES5 a ES5 [Inglese]</li> - <li><a href="http://www.youtube.com/watch?v=qbKWsbJ76-s">Forbes Lindesay: Promises and Generators: control flow utopia -- JSConf EU 2013 </a>[Inglese]</li> - <li><a href="https://www.youtube.com/watch?v=ZrgEZykBHVo&list=PLuoyIZT5fPlG44bPq50Wgh0INxykdrYX7&index=1">Hemanth.HM: The New gen of *gen(){} </a>[Inglese]</li> - <li><a href="http://taskjs.org/">Task.js </a>[Inglese]</li> - </ul> - </li> -</ul> diff --git a/files/it/web/javascript/reference/statements/import/index.html b/files/it/web/javascript/reference/statements/import/index.html deleted file mode 100644 index 9a6ac79920..0000000000 --- a/files/it/web/javascript/reference/statements/import/index.html +++ /dev/null @@ -1,167 +0,0 @@ ---- -title: import -slug: Web/JavaScript/Reference/Statements/import -translation_of: Web/JavaScript/Reference/Statements/import ---- -<div>{{jsSidebar("Statements")}}</div> - -<p>Il comando <code><strong>import</strong></code> si usa per importare bindings esportati da un altro modulo. I moduli importati sono in {{jsxref("Strict_mode","strict mode")}} indipendentemente dal fatto che venga dichiarato in modo esplicito. Il comando <code>import</code> non puo' essere usato negli script embedded.</p> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox">import <em>defaultExport</em> from "<em>module-name</em>"; -import * as <em>name</em> from "<em>module-name</em>"; -import { <em>export </em>} from "<em>module-name</em>"; -import { <em>export</em> as <em>alias </em>} from "<em>module-name</em>"; -import { <em>export1 , export2</em> } from "<em>module-name</em>"; -import { <em>export1 , export2</em> as <em>alias2</em> , <em>[...]</em> } from "<em>module-name</em>"; -import <em>defaultExport</em>, { <em>export</em> [ , <em>[...]</em> ] } from "<em>module-name</em>"; -import <em>defaultExport</em>, * as <em>name</em> from "<em>module-name</em>"; -import "<em>module-name</em>";</pre> - -<dl> - <dt><code>defaultExport</code></dt> - <dd>Nome riferito all'export di default nel modulo.</dd> - <dt><code>module-name</code></dt> - <dd>Il modulo da cui importare. E' spesso il path relativo o assoluto del file <code>.js</code> che contiene il modulo. Alcuni bundlers possono permettere o imporre l'uso dell'estensione; verifica nel tuo environment. Sono ammesse solo stringhe a singole o doppie virgolette.</dd> - <dt><code>name</code></dt> - <dd>Nome dell' oggetto-modulo che verra' usato come namespace quando si fa riferimento nelle importazioni.</dd> - <dt><code>export, exportN</code></dt> - <dd>Nome degli export da importare.</dd> - <dt><code>alias, aliasN</code></dt> - <dd>Nomi fittizi (alias) riferiti ai nomi importati.</dd> -</dl> - -<h2 id="Descrizione">Descrizione</h2> - -<p>Il parametro <code>name</code> e' il nome dell' "oggetto-modulo" che verra' usato come namespace per riferirsi agli export al suo interno. I parametri <code>export</code> indicano i nomi dei singoli export, mentre <code>import * </code>li importa tutti insieme. Seguiranno degli esempi per chiarire questa sintassi.</p> - -<h3 id="Importare_l'intero_contenuto_di_un_modulo">Importare l'intero contenuto di un modulo</h3> - -<p>L'esempio inserisce <code>myModule</code> nello scope corrente, che conterra' tutti gli export del modulo, il cui file si trova in <code>/modules/my-module.js</code>.</p> - -<pre class="brush: js">import * as <em>myModule</em> from '/modules/my-module.js'; -</pre> - -<p>Qui invece, si accede agli export usando il nome del modulo ("myModule" in this case) come namespace. Per esempio, se il modulo importato contiene l'export <code>doAllTheAmazingThings()</code>, lo indicherai in questo modo:</p> - -<pre class="brush: js">myModule.doAllTheAmazingThings();</pre> - -<h3 id="Importare_un_singolo_export_da_un_modulo">Importare un singolo export da un modulo</h3> - -<p>Dato un oggetto o valore di nome <code>myExport</code> che sia esportato dal modulo <code>my-module</code>, sia implicitamente (perche' viene esportato l'intero modulo) che esplicitamente (usando il comando {{jsxref("Statements/export", "export")}}), l'esempio che segue inserira' <code>myExport</code> nello scope corrente.</p> - -<pre class="brush: js">import {myExport} from '/modules/my-module.js';</pre> - -<h3 id="Importare_export_multipli_da_un_modulo">Importare export multipli da un modulo</h3> - -<p>In questo esempio, sia <code>foo</code> che <code>bar</code> verranno inseriti nello scope corrente.</p> - -<pre class="brush: js">import {foo, bar} from '/modules/my-module.js';</pre> - -<h3 id="Importare_un_export_usando_un_alias">Importare un export usando un alias</h3> - -<p>E' possibile rinominare un export in fase di importazione, ad esempio, <code>shortName</code> verra' inserito in questo modo nello scope corrente:</p> - -<pre class="brush: js">import {reallyReallyLongModuleExportName as shortName} - from '/modules/my-module.js';</pre> - -<h3 id="Rinominare_export_multipli_in_un_importazione">Rinominare export multipli in un importazione</h3> - -<p>Importazione multipla di export da un modulo, usando per comodita' degli alias:</p> - -<pre class="brush: js">import { - reallyReallyLongModuleExportName as shortName, - anotherLongModuleName as short -} from '/modules/my-module.js';</pre> - -<h3 id="Importare_solo_gli_'effetti_collaterali'_di_un_modulo">Importare solo gli 'effetti collaterali' di un modulo</h3> - -<p>Importazione dei soli 'effetti collaterali' di un modulo, senza importare tutto il resto. Cio' che segue eseguira' soltanto il codice nello scope globale ma senza importare alcun valore.</p> - -<pre class="brush: js">import '/modules/my-module.js'; -</pre> - -<h3 id="Importare_defaults">Importare defaults</h3> - -<p>E' possibile che in un modulo ci sia un esportazione di default {{jsxref("Statements/export", "export")}} (che sia un oggetto, una funzione, una classe, ecc...) e il comando <code>import</code> potra' servire per importarlo.</p> - -<p>La versione piu' semplice che importa direttamente il default e' questa:</p> - -<pre class="brush: js">import myDefault from '/modules/my-module.js';</pre> - -<p>E' possibile usare questa sintassi all'interno delle altre che abbiamo gia' visto (importazioni con namespace o nomi specifici) ma, in questo caso, l'importazione di default dovra' essere indicata per prima:</p> - -<pre class="brush: js">import myDefault, * as myModule from '/modules/my-module.js'; -// myModule used as a namespace</pre> - -<p>oppure</p> - -<pre class="brush: js">import myDefault, {foo, bar} from '/modules/my-module.js'; -// specific, named imports -</pre> - -<h2 id="Esempi">Esempi</h2> - -<p>Importazione di una funzione helper da un modulo secondario che processa una richiesta AJAX JSON.</p> - -<h3 id="Modulo_file.js">Modulo: file.js</h3> - -<pre class="brush: js">function getJSON(url, callback) { - let xhr = new XMLHttpRequest(); - xhr.onload = function () { - callback(this.responseText) - }; - xhr.open('GET', url, true); - xhr.send(); -} - -export function getUsefulContents(url, callback) { - getJSON(url, data => callback(JSON.parse(data))); -}</pre> - -<h3 id="Main_program_main.js">Main program: main.js</h3> - -<pre class="brush: js">import { getUsefulContents } from '/modules/file.js'; - -getUsefulContents('http://www.example.com', - data => { doSomethingUseful(data); });</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specifica</th> - <th scope="col">Status</th> - <th scope="col">Commento</th> - </tr> - <tr> - <td>{{SpecName('ES2015', '#sec-imports', 'Imports')}}</td> - <td>{{Spec2('ES2015')}}</td> - <td>Definizione iniziale.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-imports', 'Imports')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilitá">Compatibilitá</h2> - - - -<p>{{Compat("javascript.statements.import")}}</p> - -<h2 id="Vedi_anche">Vedi anche</h2> - -<ul> - <li>{{jsxref("Statements/import.meta", "import.meta")}}</li> - <li>{{jsxref("Statements/export", "export")}}</li> - <li><a href="https://blogs.windows.com/msedgedev/2016/05/17/es6-modules-and-beyond/">Previewing ES6 Modules and more from ES2015, ES2016 and beyond</a></li> - <li><a href="https://hacks.mozilla.org/2015/08/es6-in-depth-modules/">ES6 in Depth: Modules</a>, Hacks blog post by Jason Orendorff</li> - <li><a href="https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/">ES modules: A cartoon deep-dive</a>, Hacks blog post by Lin Clark</li> - <li><a class="external" href="http://exploringjs.com/es6/ch_modules.html">Axel Rauschmayer's book: "Exploring JS: Modules"</a></li> -</ul> diff --git a/files/it/web/javascript/reference/statements/index.html b/files/it/web/javascript/reference/statements/index.html deleted file mode 100644 index e997b9799f..0000000000 --- a/files/it/web/javascript/reference/statements/index.html +++ /dev/null @@ -1,131 +0,0 @@ ---- -title: Statements -slug: Web/JavaScript/Reference/Statements -tags: - - JavaScript - - NeedsTranslation - - Reference - - TopicStub - - statements -translation_of: Web/JavaScript/Reference/Statements ---- -<div>{{jsSidebar("Statements")}}</div> - -<p>JavaScript applications consist of statements with an appropriate syntax. A single statement may span multiple lines. Multiple statements may occur on a single line if each statement is separated by a semicolon. This isn't a keyword, but a group of keywords.</p> - -<h2 id="Statements_and_declarations_by_category">Statements and declarations by category</h2> - -<p>For an alphabetical listing see the sidebar on the left.</p> - -<h3 id="Control_flow">Control flow</h3> - -<dl> - <dt>{{jsxref("Statements/block", "Block")}}</dt> - <dd>A block statement is used to group zero or more statements. The block is delimited by a pair of curly brackets.</dd> - <dt>{{jsxref("Statements/break", "break")}}</dt> - <dd>Terminates the current loop, switch, or label statement and transfers program control to the statement following the terminated statement.</dd> - <dt>{{jsxref("Statements/continue", "continue")}}</dt> - <dd>Terminates execution of the statements in the current iteration of the current or labeled loop, and continues execution of the loop with the next iteration.</dd> - <dt>{{jsxref("Statements/Empty", "Empty")}}</dt> - <dd>An empty statement is used to provide no statement, although the JavaScript syntax would expect one.</dd> - <dt>{{jsxref("Statements/if...else", "if...else")}}</dt> - <dd>Executes a statement if a specified condition is true. If the condition is false, another statement can be executed.</dd> - <dt>{{jsxref("Statements/switch", "switch")}}</dt> - <dd>Evaluates an expression, matching the expression's value to a case clause, and executes statements associated with that case.</dd> - <dt>{{jsxref("Statements/throw", "throw")}}</dt> - <dd>Throws a user-defined exception.</dd> - <dt>{{jsxref("Statements/try...catch", "try...catch")}}</dt> - <dd>Marks a block of statements to try, and specifies a response, should an exception be thrown.</dd> -</dl> - -<h3 id="Declarations">Declarations</h3> - -<dl> - <dt>{{jsxref("Statements/var", "var")}}</dt> - <dd>Declares a variable, optionally initializing it to a value.</dd> - <dt>{{experimental_inline}} {{jsxref("Statements/let", "let")}}</dt> - <dd>Declares a block scope local variable, optionally initializing it to a value.</dd> - <dt>{{experimental_inline}} {{jsxref("Statements/const", "const")}}</dt> - <dd>Declares a read-only named constant.</dd> -</dl> - -<h3 id="Functions_and_classes">Functions and classes</h3> - -<dl> - <dt>{{jsxref("Statements/function", "function")}}</dt> - <dd>Declares a function with the specified parameters.</dd> - <dt>{{experimental_inline}} {{jsxref("Statements/function*", "function*")}}</dt> - <dd>Generators functions enable writing <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol">iterators</a> more easily.</dd> - <dt>{{jsxref("Statements/return", "return")}}</dt> - <dd>Specifies the value to be returned by a function.</dd> - <dt>{{experimental_inline}} {{jsxref("Statements/class", "class")}}</dt> - <dd>Declares a class.</dd> -</dl> - -<h3 id="Iterations">Iterations</h3> - -<dl> - <dt>{{jsxref("Statements/do...while", "do...while")}}</dt> - <dd>Creates a loop that executes a specified statement until the test condition evaluates to false. The condition is evaluated after executing the statement, resulting in the specified statement executing at least once.</dd> - <dt>{{jsxref("Statements/for", "for")}}</dt> - <dd>Creates a loop that consists of three optional expressions, enclosed in parentheses and separated by semicolons, followed by a statement executed in the loop.</dd> - <dt>{{deprecated_inline}} {{non-standard_inline()}} {{jsxref("Statements/for_each...in", "for each...in")}}</dt> - <dd>Iterates a specified variable over all values of object's properties. For each distinct property, a specified statement is executed.</dd> - <dt>{{jsxref("Statements/for...in", "for...in")}}</dt> - <dd>Iterates over the enumerable properties of an object, in arbitrary order. For each distinct property, statements can be executed.</dd> - <dt>{{experimental_inline}} {{jsxref("Statements/for...of", "for...of")}}</dt> - <dd>Iterates over iterable objects (including <a href="https://developer.mozilla.org/en-US/docs/Core_JavaScript_1.5_Reference/Global_Objects/Array" title="Array">arrays</a>, array-like objects, <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Iterators_and_Generators" title="Iterators and generators">iterators and generators</a>), invoking a custom iteration hook with statements to be executed for the value of each distinct property.</dd> - <dt>{{jsxref("Statements/while", "while")}}</dt> - <dd>Creates a loop that executes a specified statement as long as the test condition evaluates to true. The condition is evaluated before executing the statement.</dd> -</dl> - -<h3 id="Others">Others</h3> - -<dl> - <dt>{{jsxref("Statements/debugger", "debugger")}}</dt> - <dd>Invokes any available debugging functionality. If no debugging functionality is available, this statement has no effect.</dd> - <dt>{{experimental_inline}} {{jsxref("Statements/export", "export")}}</dt> - <dd>Used to export functions to make them available for imports in external modules, another scripts.</dd> - <dt>{{experimental_inline}} {{jsxref("Statements/import", "import")}}</dt> - <dd>Used to import functions exported from an external module, another script.</dd> - <dt>{{jsxref("Statements/label", "label")}}</dt> - <dd>Provides a statement with an identifier that you can refer to using a <code>break</code> or <code>continue</code> statement.</dd> -</dl> - -<dl> - <dt>{{deprecated_inline}} {{jsxref("Statements/with", "with")}}</dt> - <dd>Extends the scope chain for a statement.</dd> -</dl> - -<h2 id="Specifications">Specifications</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specification</th> - <th scope="col">Status</th> - <th scope="col">Comment</th> - </tr> - <tr> - <td>ECMAScript 1st Edition.</td> - <td>Standard</td> - <td>Initial definition.</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-12', 'Statements')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-ecmascript-language-statements-and-declarations', 'ECMAScript Language: Statements and Declarations')}}</td> - <td>{{Spec2('ES6')}}</td> - <td>New: function*, let, for...of, yield, class</td> - </tr> - </tbody> -</table> - -<h2 id="See_also">See also</h2> - -<ul> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators">Operators</a></li> -</ul> diff --git a/files/it/web/javascript/reference/statements/let/index.html b/files/it/web/javascript/reference/statements/let/index.html deleted file mode 100644 index 7900b7673a..0000000000 --- a/files/it/web/javascript/reference/statements/let/index.html +++ /dev/null @@ -1,208 +0,0 @@ ---- -title: let -slug: Web/JavaScript/Reference/Statements/let -translation_of: Web/JavaScript/Reference/Statements/let ---- -<div>{{jsSidebar("Statements")}}</div> - -<p>L'istruzione <strong>let </strong>dichiara una variabile locale nel blocco di codice e, facoltativamente, la inizializza ad un valore.</p> - -<div>{{EmbedInteractiveExample("pages/js/statement-let.html")}}</div> - -<div class="hidden">Il codice sorgente di questo esempio interattivo è salvato in un repository GitHub. Se tu volessi contribuire al progetto 'interactive examples', puoi clonare <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> e sottomettere una pull request.</div> - -<h2 id="Summary" name="Summary">Sintassi</h2> - -<pre class="syntaxbox notranslate">let <var>var1</var> [= <var>value1</var>] [, <var>var2</var> [= <var>value2</var>]] [, ..., <var>varN</var> [= <var>valueN</var>]]; -</pre> - -<h3 id="Parameters" name="Parameters">Parametri</h3> - -<dl> - <dt><code><var>var1</var></code>, <code><var>var2</var></code>, …, <code><var>varN</var></code></dt> - <dd>Il nome della variabile o delle variabili da dichiarare. Devono essere identificatori JavaScript validi.</dd> - <dt><code><var>value1</var></code>, <code><var>value2</var></code>, …, <code><var>valueN</var></code> {{optional_inline}}</dt> - <dd>Per ogni variabile definita, è possibile specificare il valore iniziale usando qualunque espressione JavaScript valida.</dd> -</dl> - -<h2 id="Description" name="Description">Descrizione</h2> - -<p><strong><code>let</code></strong> permette di dichiarare variabili limitandone la visibilità ad un {{jsxref("statements/block", "blocco di codice", "", 1)}}, o ad un'espressione in cui è usata, contrariamente alla parola chiave <a href="/it/docs/JavaScript/Reference/Statements/var" title="JavaScript/Reference/Statements/var"><code>var</code></a>, che invece definisce una variabile globalmente in uno script o localmente in una funzione a prescindere dal blocco di codice. L'altra differenza tra {{jsxref("statements/var", "var")}} e <code>let</code> è che la seconda è inizializzata ad un valore solo quando un parser la evaluta (vedi sotto).</p> - -<h2 id="Block_scoping" name="Block_scoping">Esempi</h2> - -<h3 id="Regole_di_visibilità">Regole di visibilità</h3> - -<p>Le variabili inizializzate da <code>let</code> sono legate al blocco dell'espressione in cui sono dichiarate. Il suo funzionamento è del tutto simile a quello di <code>var</code>, ma le variabili definite da quest'ultima istruzione sono sempre variabili globali a livello di programma o di funzione, hanno quindi una visibilità più ampia.</p> - -<pre class="notranslate">function varTest() { - var x = 1; - { - var x = 2; // same variable! - console.log(x); // 2 - } - console.log(x); // 2 -} - -function letTest() { - let x = 1; - { - let x = 2; // different variable - console.log(x); // 2 - } - console.log(x); // 1 -}</pre> - -<p>Dichiarare nuovamente la stessa variabile con <code>let</code> restituisce l'errore <code><a href="/it/docs/JavaScript/Reference/Global_Objects/TypeError" title="TypeError">TypeError</a>.</code></p> - -<pre class="brush: js notranslate"><code> -if (x) { - let foo; - let foo; // lancia un errore TypeError. -}</code></pre> - -<p>Se usata al livello più alto di programma, <code>let</code>, a differenza di <code>var</code>, non crea una proprietà seuul'oggetto globale. Per esempio:</p> - -<pre class="notranslate">var x = 'global'; -let y = 'global'; -console.log(this.x); // "global" -console.log(this.y); // undefined</pre> - -<p>Potresti imbatterti in errori in un blocco <a href="/it/docs/JavaScript/Reference/Statements/switch" title="switch"><code>switch</code></a> perché i casi non vengono separati ma fanno parte tutti dello stesso blocco.</p> - -<pre class="brush: js notranslate"><code> -switch (x) { - case 0: - let foo; - break; - - case 1: - let foo; // TypeError for redeclaration. - break; -}</code></pre> - -<h2 id="Examples" name="Examples"><code>Esempi</code></h2> - -<p>Una <em><code>let</code> expression</em> può essere usata per limitare la visibilità della variabile dichiarata alla sola espressione chiamata.</p> - -<pre class="brush: js notranslate"><code> -var a = 5; -let(a = 6) alert(a); // 6 -alert(a); // 5</code></pre> - -<p>Usando <code>let</code> in un blocco di codice ne limitiamo la visibilità al solo blocco racchiuso. Nel codice di esempio nota come le due assegnazioni nel blocco <code>if</code> diano due risultati diversi.</p> - -<pre class="brush: js notranslate"><code> -var a = 5; -var b = 10; - -if (a === 5) { - let a = 4; // La visibilità è dentro il blocco if - var b = 1; // La visibilità è dentro la funzione - - console.log(a); // 4 - console.log(b); // 1 -} - -console.log(a); // 5 -console.log(b); // 1</code></pre> - -<p>Puoi usare <strong><code>let</code></strong> come iteratore in un ciclo <strong><code>for</code></strong> invece di usare una nuova variabile globale.</p> - -<pre class="brush: js notranslate"><code> -for (let i = 0; i<10; i++) { - alert(i); // 1, 2, 3, 4 ... 9 -} - -alert(i); // i non è definita</code></pre> - -<p>Quando lavori con i costruttori puoi usare <code>let</code> per creare in'interfaccia privata senza chiusure.</p> - -<pre class="brush: js notranslate"><code> -/*\ -|*| -|*| :: Una API pubblica e riutilizzabile per i costruttori ... :: -|*| -\*/ - -let ( - switchScope = function (oOwner, fConstructor) { - return oOwner && oOwner.constructor === fConstructor ? oOwner : this; - } -) { - function buildIndoors (fConstructor) { - const oPrivate = new fConstructor(this); - this.getScope = oPrivate.getScope = switchScope.bind(this, oPrivate); - return oPrivate; - } -} - -/*\ -|*| -|*| :: Use of the *let* statement in order to create a private interface without closures... :: -|*| -\*/ - -let ( - - /* "Secrets" is the constructor of the private interface */ - - Secrets = function Secrets (oPublic /* (the public interface) */) { - /* setting a private property... */ - this.password = Math.floor(Math.random() * 1e16).toString(36); - /* you can also store the public interface into a private property... */ - /* this.publicInterface = oPublic; */ - alert("I\'m getting a public property from a private constructor...: somePublicProperty: " + oPublic.somePublicProperty); - } - -) { - - /* "User" is the constructor of the public interface */ - - function User (sNick) { - /* setting a public property... */ - this.somePublicProperty = "Hello World!"; - const oPrivate = this.createScope(Secrets); /* (the private interface) */ - /* setting a public property... */ - this.user = sNick; - alert("I\'m getting a private property from a public constructor...: password: " + oPrivate.password); - } - - User.prototype.somePublicMethod = function () { - const oPrivate = this.getScope(Secrets); /* (the private interface) */ - alert("I\'m getting a public property from a public method...: user: " + this.user); - alert("I\'m getting a private property from a public method...: password: " + oPrivate.password); - oPrivate.somePrivateMethod(); - }; - - Secrets.prototype.somePrivateMethod = function () { - const oPublic = this.getScope(); /* (the public interface) */ - alert("I\'m getting a public property from a private method...: user: " + oPublic.user); - alert("I\'m getting a private property from a private method...: password: " + this.password); - }; - - /* ...creating a mutual access... */ - - User.prototype.createScope = buildIndoors; -} - -/* out of the *let* statement you have not access to the private interface! */ - -const johnSmith = new User("John Smith"); -johnSmith.somePublicMethod();</code></pre> - -<h2 id="Browser_compatibility">Browser compatibility</h2> - -<div class="hidden">The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</div> - -<p>{{Compat("javascript.statements.let")}}</p> - -<h2 id="See_also" name="See_also"></h2> - -<h2 id="See_also" name="See_also"><code>See also</code></h2> - -<ul> - <li><code><a href="/it/docs/JavaScript/Reference/Statements/var" title="JavaScript/Reference/Statements/var"><code>var</code></a></code></li> - <li><code><a href="/it/docs/JavaScript/Reference/Statements/const" title="JavaScript/Reference/Statements/const"><code>const</code></a></code></li> - <li><code><a href="/it/docs/JavaScript/New_in_JavaScript/1.7#Block_scope_with_let_(Merge_into_let_Statement)" title="JavaScript/New in JavaScript/1.7#Block scope with let (Merge into let Statement)">New in JavaScript 1.7</a></code></li> -</ul> diff --git a/files/it/web/javascript/reference/statements/switch/index.html b/files/it/web/javascript/reference/statements/switch/index.html deleted file mode 100644 index aef4d668ce..0000000000 --- a/files/it/web/javascript/reference/statements/switch/index.html +++ /dev/null @@ -1,320 +0,0 @@ ---- -title: switch -slug: Web/JavaScript/Reference/Statements/switch -tags: - - JavaScript - - Reference - - Statement - - Web -translation_of: Web/JavaScript/Reference/Statements/switch ---- -<div>{{jsSidebar("Statements")}}</div> - -<p><span class="seoSummary"><code>Il<strong> comando</strong></code><strong><code>switch</code></strong> valuta un <a href="/it-IT/docs/Web/JavaScript/Guide/Expressions_and_Operators">espressione</a>, confronta il valore dell'espressione con ciascuna delle clausole <code>case</code> ed esegue i <a href="/it-IT/docs/Web/JavaScript/Reference/Statements">comandi</a> (<a href="/en-US/docs/Web/JavaScript/Reference/Statements">statements</a>) associati alla clausola (<code>case</code>) che verifica il confronto.</span></p> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox">switch (espressione) { - case valore1: - //Comandi eseguiti quando il valore dell'espressione coincide con valore1 - [break;] - case valore2: - //Comandi eseguiti quando il valore dell'espressione coincide con valore2 - [break;] - ... - case valoreN: - //Comandi eseguiti quando il valore dell'espressione coincide con valoreN - [break;] - default: - //Comandi eseguiti quando nessuno dei valori coincide col valore dell'epressione - [break;] -}</pre> - -<dl> - <dt><code>espressione</code></dt> - <dd>Un'espressione il cui risultato è confrontato con ogni clausola case.</dd> - <dt><code>case valoreN</code></dt> - <dd>Clausola case usata nel confronto con l' <code>espressione</code>.</dd> - <dt><code>default</code></dt> - <dd>Una clausola <code>default</code> è facoltativa e, se specificata, la clausola viene eseguita se il valore dell'<code>espressione</code> non corrisponde a nessuna clausola <code>case</code>.</dd> -</dl> - -<h2 id="Descrizione">Descrizione</h2> - -<p>Un comando switch per prima cosa valuta <code>espressione</code>; poi cerca la prima clausola <code>case</code> la cui essa ha lo stesso valore del risultato dell'espressione di <code>switch</code> (utilizzando la <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators">strict comparison</a>, <code>===</code>); quindi il comando <code>switch</code> trasferisce il controllo alla clausola <code>case</code>, eseguendone i comandi. Se più clausole <code>case</code> sono verificate dal confronto con l'espressione di <code>switch</code>, viene scelta la prima che verifica il confronto, anche se le clausole non sono uguali. Se nessuna clausola <code>case</code> risulta verificata dal confronto, il programma cerca la clausola facoltativa <code>default</code>, e se la trova, trasferisce il controllo a questa, eseguendone i comandi. Se non viene trovata alcuna clausola <code>default</code>, il programma continua eseguendo il comando successivo alla fine del comando <code>switch</code>. Convenzionalmente, ma non necessariamente, la clausola <code>default</code> è l'ultima clausola.</p> - -<p>Il comando facoltativo <code><a href="/en-US/docs/Web/JavaScript/Reference/Statements/break" title="JavaScript/Reference/Statements/break">break</a></code> associato a ciascuna etichetta <code>case</code> assicura che, una volta eseguiti i comandi della clausola che verifica l'espressione di <code>switch</code>, il programma interrompa il comando switch e che continui eseguendo il comando successivo. Se il comando <code>break</code> viene omesso, il programma continua l'esecuzione dal comando successivo all'interno del comando di <code>switch</code>, quindi dal primo della successiva clausola <code>case</code>.</p> - -<h2 id="Esempi">Esempi</h2> - -<h3 id="Utilizzo_di_switch">Utilizzo di <code>switch</code></h3> - -<p>Nell'esempio seguente, se <code>expr</code> vale "Banane", il programma confronta il valore con la clausola "Banane" ed esegue i comandi associati. Quando incontra <code>break</code>, il programma interrompe il comando <code>switch</code> ed esegue il comando successivo a <code>switch</code>. Se <code>break</code> fosse omesso, sarebbero eseguiti anche i comandi della clausola "Ciliegie".</p> - -<pre class="brush: js">switch (expr) { - case "Arance": - console.log("Le arance costano €1,0 al chilo."); - break; - case "Mele": - console.log("Le mele costano €0.64 al chilo."); - break; - case "Banane": - console.log("Le banane costano €0.92 al chilo."); - break; - case "Ciliege": - console.log("Le ciliegie costano €2.59 al chilo."); - break; - case "Manghi": - case "Papaye": - console.log("I manghi e le papaye costano €1.79 al chilo."); - break; - default: - console.log("Spiacenti, non abbiamo " + expr + "."); -} - -console.log("Desidera qualcos'altro ?"); -</pre> - -<h3 id="Cosa_accade_se_dimentico_un_break">Cosa accade se dimentico un <font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(255, 255, 255, 0.4);">break</span></font>?</h3> - -<p>Se vi dimenticate un break, lo script partirà dalla clausola il cui criterio è verificato, e proseguirà con la clausola successiva anche se il criterio non era verifcato. Ecco alcuni esempi:</p> - -<pre class="brush: js">var foo = 0; -switch (foo) { - case -1: - console.log('1 negativo'); - break; - case 0: // foo è 0 quindi il criterio è verificato; questo blocco verrà eseguito - console.log(0); - // NOTA: il break dimenticato sarebbe dovuto essere qui - case 1: // manca il comando break in 'case 0:' quindi anche questo blocco sarà eseguito - console.log(1); - break; // incontra questo break così con proseguirà in 'case 2:' - case 2: - console.log(2); - break; - default: - console.log('default'); -}</pre> - -<h3 id="Posso_mettere_un_default_in_mezzo">Posso mettere un <font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(255, 255, 255, 0.4);">default</span></font> in mezzo?</h3> - -<p>Certo che puoi! JavaScript passerà al default se non troverà nessun criterio corrispondente:</p> - -<pre><code>var foo = 5; -switch (foo) { - case 2: - console.log(2); - break; // incontra un break, quindi non procederà automaticamente su "default:" - default: - console.log('default') - // non c'è un break, quindi verrà eseguito anche il contenuto di "case 1:"! - case 1: - console.log('1'); -}</code></pre> - -<p>Funziona anche se metti default prima di ogni altra clausola.</p> - -<h3 id="Riscrivere_molteplici_istruzioni_If_con_Switch">Riscrivere molteplici istruzioni If con Switch</h3> - -<p>Di seguito viene fornito un esempio:</p> - -<pre><code>var a = 100; -var b = NaN; -switch (true) { - case isNaN(a) || isNaN(b): - console.log('NaNNaN'); - break; - case a === b: - console.log(0); - break; - case a < b: - console.log(-1); - break; - default: - console.log(1); -}</code></pre> - - - -<h3 id="Metodi_per_i_case_con_più_criteri">Metodi per i <code>case</code> con più criteri</h3> - -<p>I sorgenti per questa tecnica possono essere scaricati qui:</p> - -<p><a href="http://stackoverflow.com/questions/13207927/switch-statement-multiple-cases-in-javascript">Switch statement multiple cases in JavaScript (Stack Overflow)</a></p> - -<h4 id="Multi-case_-_operazione_singola">Multi-case - operazione singola</h4> - -<p>Questo metodo si avvale del fatto che se non c'è un <code>break</code> break prima di un comando di <code>case</code> continuerà eseguento il successivo comando di <code>case</code> ingnorando se verifica il criterio di esecuzione. Vedi la sezione "Cosa accade se dimentico un <code>break</code>?"</p> - -<p>Questo è un esempio di un comando di switch a singola operazione sequenziale, dove quattro valori diversi realizzano la stessa cosa.</p> - -<pre class="brush: js">var Animale = 'Giraffa'; -switch (Animale) { - case 'Mucca': - case 'Giraffa': - case 'Cane': - case 'Maiale': - console.log('Queso animale anndrà sull'Arca di Noè.'); - break; - case 'Dinosauro': - default: - console.log('Questo animale non andrà.'); -}</pre> - -<h4 id="Multi-case_-_operazioni_concatenate">Multi-case - operazioni concatenate</h4> - -<p>Questo è un esempio di un comando di switch ad operazione multipla sequenziale, dove, a seconda del numero intero fornito, si ricevono diversi output. Mostra come sia possibile sfruttare l'ordine in cui sono scritte le clausole, e come non debbano essere numericamente in sequenza. In JavaScript, si possono anche inserire definizioni di stringhe nei comandi case.</p> - -<pre class="brush: js">var foo = 1; -var output = 'Output: '; -switch (foo) { - case 10: - output += 'quindi '; - case 1: - output += 'quale '; - output += 'è '; - case 2: - output += ' il tuo '; - case 3: - output += 'nome'; - case 4: - output += '?'; - console.log(output); - break; - case 5: - output += '!'; - console.log(output); - break; - default: - console.log('Per favore prendere un numero da 1 a 5 o 10!'); -}</pre> - -<p>Output per questo esempio:</p> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Valore</th> - <th scope="col">Testo di log</th> - </tr> - <tr> - <td>foo è diverso da 1, 2, 3, 4, 5 or 10</td> - <td>Per favore prendere un numero da 1 a 5 o 10!</td> - </tr> - <tr> - <td>10</td> - <td>Output: quindi quale è il tuo nome?</td> - </tr> - <tr> - <td>1</td> - <td>Output: quale è il tuo nome?</td> - </tr> - <tr> - <td>2</td> - <td>Output: il tuo nome?</td> - </tr> - <tr> - <td>3</td> - <td>Output: nome?</td> - </tr> - <tr> - <td>4</td> - <td>Output: ?</td> - </tr> - <tr> - <td>5</td> - <td>Output: !</td> - </tr> - </tbody> -</table> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specifiche</th> - <th scope="col">Status</th> - <th scope="col">Commento</th> - </tr> - <tr> - <td>{{SpecName('ES3')}}</td> - <td>{{Spec2('ES3')}}</td> - <td>Definizione iniziale. Relaizzata in JavaScript 1.2</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-12.11', 'switch statement')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-switch-statement', 'switch statement')}}</td> - <td>{{Spec2('ES6')}}</td> - <td></td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-switch-statement', 'switch statement')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td></td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_dei_browser">Compatibilità dei browser</h2> - -<p>{{CompatibilityTable}}</p> - -<div id="compat-desktop"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Chrome</th> - <th>Firefox (Gecko)</th> - <th>Internet Explorer</th> - <th>Opera</th> - <th>Safari</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<div id="compat-mobile"> -<table class="compat-table"> - <tbody> - <tr> - <th>Feature</th> - <th>Android</th> - <th>Chrome for Android</th> - <th>Firefox Mobile (Gecko)</th> - <th>IE Mobile</th> - <th>Opera Mobile</th> - <th>Safari Mobile</th> - </tr> - <tr> - <td>Basic support</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - <td>{{CompatVersionUnknown}}</td> - </tr> - </tbody> -</table> -</div> - -<h2 id="Vedi_anche">Vedi anche</h2> - -<ul> - <li><a href="/it-IT/docs/Web/JavaScript/Reference/Statements/if...else"><code>if...else</code></a></li> -</ul> diff --git a/files/it/web/javascript/reference/statements/throw/index.html b/files/it/web/javascript/reference/statements/throw/index.html deleted file mode 100644 index 1aecd9ca9a..0000000000 --- a/files/it/web/javascript/reference/statements/throw/index.html +++ /dev/null @@ -1,195 +0,0 @@ ---- -title: throw -slug: Web/JavaScript/Reference/Statements/throw -tags: - - JavaScript - - Statement -translation_of: Web/JavaScript/Reference/Statements/throw ---- -<div>{{jsSidebar("Statements")}}</div> - -<p>L'istruzione <strong><code>throw</code> </strong>chiama un'eccezione definita dall'utente. L'esecuzione della funzione corrente si interrompe (ovvero i comandi successivi a <code>throw</code> non verranno eseguiti), e il controllo verrà passato al primo blocco <a href="/en-US/docs/Web/JavaScript/Reference/Statements/try...catch"><code>catch</code></a> nella pila delle chiamate. Se non è previsto nessun blocco <code>catch</code> esiste nella funzione chiamante, il programma verrà terminato.</p> - -<div>{{EmbedInteractiveExample("pages/js/statement-throw.html")}}</div> - -<p class="hidden">Il codice sorgente per questo esempio è disponibile su una repository di GitHub. Se ti piacerebbe contribuire al progetto interattivo d'esempio, clona <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> e poi inviaci una pull request.</p> - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox">throw <em>espressione</em>; </pre> - -<dl> - <dt><code>espressione</code></dt> - <dd>L'espressione da chiamare.</dd> -</dl> - -<h2 id="Descrizione">Descrizione</h2> - -<p>Usa l'istruzione <code>throw</code> per chiamare un'eccezione. Quando chiami un'eccezione, l'<code>espressione</code> specifica il valore dell'eccezione. Ognuna delle seguenti righe chiama un'eccezione.</p> - -<pre class="brush: js">throw 'Error2'; // genera un'eccezione con una stringa con valore Error2 -throw 42; // genera un'eccezione con valore 42 -throw true; // genera un'eccezione con valore true</pre> - -<p>Nota bene che l'istruzione <code>throw</code> viene gestita dall'<a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Automatic_semicolon_insertion">automatic semicolon insertion (ASI)</a> e quindi non puoi andare a capo fra <code>throw</code> e l'espressione.</p> - -<h2 id="Esempi">Esempi</h2> - -<h3 id="Chiama_un_oggetto">Chiama un oggetto</h3> - -<p>Puoi specificare un oggetto quando chiami un eccezione. In seguito puoi riportare le proprietà dell'oggetto nel blocco <code>catch</code>. L'esempio seguente crea un oggetto di tipo <code>UserException</code> e poi lo usa nell'istruzione <code>throw</code>.</p> - -<pre class="brush: js">function UserException(message) { - this.message = message; - this.name = 'UserException'; -} -function getMonthName(mo) { - mo = mo - 1; // Adjust month number for array index (1 = Jan, 12 = Dec) - var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', - 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; - if (months[mo] !== undefined) { - return months[mo]; - } else { - throw new UserException('InvalidMonthNo'); - } -} - -try { - // statements to try - var myMonth = 15; // 15 is out of bound to raise the exception - var monthName = getMonthName(myMonth); -} catch (e) { - monthName = 'unknown'; - console.log(e.message, e.name); // pass exception object to err handler -} -</pre> - -<h3 id="Un_altro_esempio_di_chiamata_ad_un_oggetto">Un altro esempio di chiamata ad un oggetto</h3> - -<p>L'esempio seguente testa una stringa in input per un codice postale di avviamento postale (CAP) americano. Se il CAP fornito è in un formato non valido, l'istruzione throw chiama un'eccezione creando un oggetto di tipo <code>ZipCodeFormatException</code>.</p> - -<pre class="brush: js">/* - * Creates a ZipCode object. - * - * Accepted formats for a zip code are: - * 12345 - * 12345-6789 - * 123456789 - * 12345 6789 - * - * If the argument passed to the ZipCode constructor does not - * conform to one of these patterns, an exception is thrown. - */ - -function ZipCode(zip) { - zip = new String(zip); - pattern = /[0-9]{5}([- ]?[0-9]{4})?/; - if (pattern.test(zip)) { - // zip code value will be the first match in the string - this.value = zip.match(pattern)[0]; - this.valueOf = function() { - return this.value - }; - this.toString = function() { - return String(this.value) - }; - } else { - throw new ZipCodeFormatException(zip); - } -} - -function ZipCodeFormatException(value) { - this.value = value; - this.message = 'does not conform to the expected format for a zip code'; - this.toString = function() { - return this.value + this.message; - }; -} - -/* - * This could be in a script that validates address data - * for US addresses. - */ - -const ZIPCODE_INVALID = -1; -const ZIPCODE_UNKNOWN_ERROR = -2; - -function verifyZipCode(z) { - try { - z = new ZipCode(z); - } catch (e) { - if (e instanceof ZipCodeFormatException) { - return ZIPCODE_INVALID; - } else { - return ZIPCODE_UNKNOWN_ERROR; - } - } - return z; -} - -a = verifyZipCode(95060); // returns 95060 -b = verifyZipCode(9560); // returns -1 -c = verifyZipCode('a'); // returns -1 -d = verifyZipCode('95060'); // returns 95060 -e = verifyZipCode('95060 1234'); // returns 95060 1234 -</pre> - -<h3 id="Richiamare_un'eccezione">Richiamare un'eccezione</h3> - -<p>Puoi usare <code>throw</code> per richiamare un'eccezione dopo averla già gestita. L'esempio seguente gestisce un'eccezione con un valore numerico e la richiama se tale valore supera 50. Un'eccezione richiamata si propaga fino alla funzione che la racchiude oppure fino al livello più alto in modo che l'utente la veda.</p> - -<pre class="brush: js">try { - throw n; // throws an exception with a numeric value -} catch (e) { - if (e <= 50) { - // statements to handle exceptions 1-50 - } else { - // cannot handle this exception, so rethrow - throw e; - } -} -</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specification</th> - <th scope="col">Status</th> - <th scope="col">Comment</th> - </tr> - <tr> - <td>{{SpecName('ES3')}}</td> - <td>{{Spec2('ES3')}}</td> - <td>Definizione iniziale. Implementata in JavaScript 1.4</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-12.13', 'throw statement')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-throw-statement', 'throw statement')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-throw-statement', 'throw statement')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_dei_browser">Compatibilità dei browser</h2> - -<div class="hidden">La tabella di compatibilità dei browser è generata da dati strutturati. Se ti piacerebbe contribuire ai dati, controlla <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> e inviaci una pull request.</div> - -<p>{{Compat("javascript.statements.throw")}}</p> - -<h2 id="Vedi_anche">Vedi anche</h2> - -<ul> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/try...catch"><code>try...catch</code></a></li> -</ul> diff --git a/files/it/web/javascript/reference/statements/var/index.html b/files/it/web/javascript/reference/statements/var/index.html deleted file mode 100644 index 41ee508d3c..0000000000 --- a/files/it/web/javascript/reference/statements/var/index.html +++ /dev/null @@ -1,221 +0,0 @@ ---- -title: var -slug: Web/JavaScript/Reference/Statements/var -tags: - - Dichiarazioni - - Globali - - JavaScript - - Locali - - Valore - - Variabili - - funzione -translation_of: Web/JavaScript/Reference/Statements/var ---- -<div>{{jsSidebar("Statements")}}</div> - -<p>La dichiarazione <strong><code>variabile</code> </strong> dichiara una variabile, opzionalmente inizializzabile ad un valore.</p> - -<div>{{EmbedInteractiveExample("pages/js/statement-var.html")}}</div> - - - -<h2 id="Sintassi">Sintassi</h2> - -<pre class="syntaxbox">var <em>nomevariabile1 [</em>= <em>valore1] [</em>, <em>nomevariabile2 [</em>= <em>valore2] </em><em>... [</em>, <em>nomevariabileN [</em>= <em>valoreN]]]</em>;</pre> - -<dl> - <dt><code>nomevariabileN</code></dt> - <dd>Il nome della variabile. Può essere qualunque identificatore legale.</dd> -</dl> - -<dl> - <dt><code>valoreN</code></dt> - <dd>Valore iniziale della variabile. Può essere qualunque espressione legale. Il valore di default è <em>undefined</em> (non definito).</dd> -</dl> - -<h2 id="Descrizione"> Descrizione</h2> - -<p>Le dichiarazioni di variabile, ovunque appaiano, sono processate prima dell'esecuzione di qualsiasi codice. L'ambiente di una variabile dichiarata con <code>var</code> è il suo attuale <em>contesto di esecuzione</em>, che è la funzione di chiusura o, per le variabili dichiarate al di fuori di qualsiasi funzione, globale. Se si dichiara nuovamente una variabile JavaScript, il suo valore non sarà perso.</p> - -<p>Assegnando un valore a una variabile non dichirata la rende implicitamente globale (diventa una proprietà dell'oggetto) quando viene eseguita. Le differenze fra variabili dichiarate e non dichiarate sono:</p> - -<p>1. Le variabili dichiarate sono legate al contesto in cui sono dichiarate. Quelle non dichiarate sono sempre globali.</p> - -<pre class="brush: js">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 -</pre> - -<p>2. Variabili dichiarate sono create prima dell'esecuzione del codice. Variabili non dichiarate non esistono finchè il codice assegnato loro non viene eseguito.</p> - -<pre class="brush: js">console.log(a); // Genera un ReferenceError. -console.log('still going...'); // Non verrà eseguito.</pre> - -<pre class="brush: js">var a; -console.log(a); // scrive in console "undefined" o "" a seconda del browser usato. -console.log('still going...'); // scrive in console "still going...".</pre> - -<p>3. Variabili dichiarate diventano una proprietà non configurabile del loro contesto di esecuzione (funzione o globale). Quelle non dichiarate sono configurabili (per esempio, possono essere cancellate).</p> - -<pre class="brush: js">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ù.</pre> - -<p>A causa di queste tre differenze, il fallimento della dichiarazione di variabile porta molto probabilmente a risultati inaspettati. Pertanto <strong>è raccomandato di dichiarare sempre le variabili, indipendentemente dal loro contesto di appartenenza (funzione o globale).</strong> In ECMAScript 5 <a href="/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode">strict mode</a>, assegnare una variabile non dichiarata genera un errore.</p> - -<h3 id="Hoisting_di_var">Hoisting di var</h3> - -<p>Poichè le dichiarazioni di variabile (come le dichiarazioni in generale) sono processate prima dell'esecuzione del codice, dichiararne una in qualsiasi punto del codice è equivalente al dichiararle in cima. Questo significa anche che quella variabile può essere usata prima della dichiarazione. Questo comportamento è chiamato "hoisting" (sollevamento, innalzamento), poichè sembra che la dichiarazione di variabile sia portata in cima alla funzione o al codice globale.</p> - -<pre class="brush: js">bla = 2; -var bla; -// ... - -// è implicitamente interpretato come: - -var bla; -bla = 2; -</pre> - -<p>Per questa ragione, è consigliato sempre dichiarare le variabili in cima al loro ambiente (in cima al codice globale o della funzione in cui appaiono) al fine di rendere chiaro quali variabili appartengono alle funzioni (locali) e quali no.</p> - -<p>È importante precisare che l'hoisting è applicato alla dichiarazione della variabile, ma non all'inizializzazione del suo valore. Il valore verrà infatti assegnato al raggiungimento della dichiarazione :</p> - -<pre class="brush: js">function fai_qualcosa() { - console.log(bar); // non definito - var bar = 111; - console.log(bar); // 111 -} - -// è implicitamente interpretato come: -function fai_qualcosa() { - var bar; - console.log(bar); // non definito - bar = 111; - console.log(bar); // 111 -} -</pre> - -<p> </p> - -<h2 id="Esempi">Esempi</h2> - -<h3 id="Dichiarare_e_inizializzare_due_variabili">Dichiarare e inizializzare due variabili</h3> - -<pre class="brush: js">var a = 0, b = 0; -</pre> - -<h3 id="Assegnare_un_singolo_valore_stinga_a_due_variabili">Assegnare un singolo valore stinga a due variabili</h3> - -<pre class="brush: js">var a = 'A'; -var b = a; - -// è come dire: - -var a, b = a = 'A'; -</pre> - -<p>Prestare attenzione all'ordine:</p> - -<pre class="brush: js">var x = y, y = 'A'; -console.log(x + y); // non definito -</pre> - -<p>Qui, <code>x</code> e <code>y</code> sono dichiarate prima dell'esecuzione del codice, gli assegnamenti verranno eseguiti in seguito. Nel momento in cui "<code>x = y</code>" viene valutato, <code>y</code> esiste quindi nessun <code>ReferenceError</code> viene generato e il suo valore risulta essere '<code>undefined</code>' (non definit). Quindi, <code>x</code> è assegnata ad un valore non definito. Ora, ad <code>y</code> è assegnato il valore 'A'. Di conseguenza, dopo la prima riga, <code>x === undefined && y === 'A'</code>. Da qui il risultato.</p> - -<h3 id="Inizializzazione_di_più_variabili">Inizializzazione di più variabili</h3> - -<pre class="brush: js">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!</pre> - -<h3 id="Globali_implicite_e_ambienti_esterni_alle_funzioni">Globali implicite e ambienti esterni alle funzioni</h3> - -<p><span lang="it">Le variabili che sembrano essere globali implicite possono essere riferimenti a variabili nell'ambito di una funzione esterna:</span></p> - -<pre class="brush: js">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</pre> - -<h2 id="Specifiche">Specifiche</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Specifica</th> - <th scope="col">Stato</th> - <th scope="col">Commento</th> - </tr> - <tr> - <td>{{SpecName('ES1')}}</td> - <td>{{Spec2('ES1')}}</td> - <td>Definizione iniziale, implementata in JavaScript 1.0</td> - </tr> - <tr> - <td>{{SpecName('ES5.1', '#sec-12.2', 'var statement')}}</td> - <td>{{Spec2('ES5.1')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ES6', '#sec-variable-statement', 'variable statement')}}</td> - <td>{{Spec2('ES6')}}</td> - <td> </td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-variable-statement', 'variable statement')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilità_Browser">Compatibilità Browser</h2> - - - -<p>{{Compat("javascript.statements.var")}}</p> - -<h2 id="Guarda_anche">Guarda anche</h2> - -<ul> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/let"><code>let</code></a></li> - <li><a href="/en-US/docs/Web/JavaScript/Reference/Statements/const"><code>const</code></a></li> -</ul> |