diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:17 -0500 |
commit | da78a9e329e272dedb2400b79a3bdeebff387d47 (patch) | |
tree | e6ef8aa7c43556f55ddfe031a01cf0a8fa271bfe /files/it/web/javascript/reference/global_objects/undefined | |
parent | 1109132f09d75da9a28b649c7677bb6ce07c40c0 (diff) | |
download | translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.gz translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.bz2 translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.zip |
initial commit
Diffstat (limited to 'files/it/web/javascript/reference/global_objects/undefined')
-rw-r--r-- | files/it/web/javascript/reference/global_objects/undefined/index.html | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/files/it/web/javascript/reference/global_objects/undefined/index.html b/files/it/web/javascript/reference/global_objects/undefined/index.html new file mode 100644 index 0000000000..d16ca712cf --- /dev/null +++ b/files/it/web/javascript/reference/global_objects/undefined/index.html @@ -0,0 +1,173 @@ +--- +title: undefined +slug: Web/JavaScript/Reference/Global_Objects/undefined +translation_of: Web/JavaScript/Reference/Global_Objects/undefined +--- +<div> +<div> +<div>{{jsSidebar("Objects")}}</div> +</div> +</div> + +<h2 id="Summary" name="Summary">Sommario</h2> + +<p>La variabile globale <strong><code>undefined</code></strong> rappresenta il valore primitivo <span style="font-family: Consolas,Monaco,'Andale Mono',monospace;">{{Glossary("Undefined", "undefined")}}</span>. È uno dei {{Glossary("Primitive", "valori primitivi")}} di JavaScript.</p> + +<p>{{js_property_attributes(0,0,0)}}</p> + +<h2 id="Syntax" name="Syntax">Sintassi</h2> + +<pre class="syntaxbox"><code>undefined</code></pre> + +<h2 id="Description" name="Description">Descrizione</h2> + +<p><code>undefined</code> è una proprietà dell'<em>oggetto globale</em>, ossia una variablie nel contesto globale. Il valore iniziale di <code>undefined</code> è il valore primitivo <span style="font-family: Consolas,Monaco,'Andale Mono',monospace;">{{Glossary("Undefined", "undefined")}}</span>. </p> + +<p>Secondo la specifica ECMAScript5, <code>undefined</code> è accessibile in sola lettura (implementato in JavaScript 1.8.5 / Firefox 4).</p> + +<p>Una variabile alla quale non è ancora stato assegnato un valore è di tipo undefined. Un metodo o una dichiarazione restituisce <code>undefined</code> se la variabile che viene valutata non ha un valore assegnato. Una funzione restituisce <code>undefined</code> se non viene restituito un altro valore.</p> + +<p>Siccome <code>undefined</code> non è una {{jsxref("Reserved_Words", "parola riservata")}}, può essere usato come <a href="/en-US/docs/Web/JavaScript/Guide/Values,_variables,_and_literals#Variables">nome di una variabile</a> in qualsiasi contesto, eccetto quello globale.</p> + +<pre class="brush: js">// logs "foo string" +(function(){ var undefined = 'foo'; console.log(undefined, typeof undefined); })(); + +// logs "foo string" +(function(undefined){ console.log(undefined, typeof undefined); })('foo'); +</pre> + +<h2 id="Esempi">Esempi</h2> + +<h3 id="undefined_e_l'uguaglianza_ristretta"><code>undefined</code> e l'uguaglianza ristretta</h3> + +<p>Puoi usare <code>undefined</code> e gli operatori "<em>strettamente uguale"</em> e "<em>strettamente diverso</em>" per determinare se ad una variabile è stato assegnato un valore. In questo codice, la variabile <code>x</code> non è definita, qundi l'istruzione <code>if</code> viene valutata vera.</p> + +<pre class="brush: js">var x; + +x === undefined; // true +</pre> + +<div class="note"><strong>Nota:</strong> Qui devono essere utilizzati gli operatori di uguaglianza stretta, perché <code>x == undefined</code> è vero anche se <code>x</code> è <code>null</code>, mentre confrontandoli con l'ugualianza stretta no. <code>null</code> e <code>undefined</code> non sono equivalenti. Vedi gli {{jsxref("Operators/Comparsion_Operators", "operatori di comparazione")}} per altri dettagli.</div> + +<h3 id="undefined_e_l'operatore_typeof"><code>undefined</code> e l'operatore <code>typeof</code></h3> + +<p>In alternativa può anche essere usato l'operatore <code>{{jsxref("Operators/typeof", "typeof")}}:</code></p> + +<pre class="brush: js">var x; + +typeof x === 'undefined'; // true +</pre> + +<p>Un motivo per cui usare l'operatore <code>{{jsxref("Operators/typeof", "typeof")}}</code> è che se la variabile non stata dichiarata non viene generato un errore.</p> + +<pre class="brush: js">// x non è ancora stata dichiarata + +typeof x === "undefined"; // viene valutata come vera, senza generare erroi + +x === undefined; // genera un ReferenceError +</pre> + +<p>Comunque questa tecnica dovrebbe essere evitata. JavaScript è un linguaggio staticamente contestualizzato, quindi si può sapere se una variabile è stata dichiarata in un contesto guardando in quelli che lo contengono. L'unica eccezione è il contesto globale, che è rappresentato dall'<em>oggetto globale</em>: quindi per sapere se esiste una variabile basta controllare se esiste una proprietà nell'<em>oggetto globale</em> (per esempio usando l'operatore {{jsxref("Operators/in", "in")}} o il metodo {{jsxref("Global_Objects/Object/hasOwnProperty", "hasOwnProperty")}})</p> + +<pre class="brush: js">// x non è ancora stata dichiarata + +"x" in window; // false +window.hasOwnProperty("x"); // false + +var x = 3; + +"x" in window; // true +window.hasOwnProperty("y"); // true +</pre> + +<h3 id="undefined_e_l'operatore_void"><code>undefined</code> e l'operatore <code>void</code></h3> + +<p>Una terza alternativa è l'operatore {{jsxref("Operators/void", "<code>void</code>")}}.</p> + +<pre class="brush: js">var x; +x === void 0; // true + +// y non è ancora stata dichiarata +y === void 0; // genera un ReferenceError (a differenza di `typeof`) +</pre> + +<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>Definizione iniziale. Implementato in JavaScript 1.3</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.1.1.3', 'undefined')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-undefined', 'undefined')}}</td> + <td>{{Spec2('ES6')}}</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>Funzionalità</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Supporto di base</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><span style="font-family: 'Open Sans Light',sans-serif; font-size: 16px; line-height: 16px;">Funzionalità</span></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><span style="font-size: 12px; line-height: 18px;">Supporto di base</span></td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<p> </p> |