diff options
Diffstat (limited to 'files/it/conflicting/web/javascript/reference')
3 files changed, 686 insertions, 0 deletions
diff --git a/files/it/conflicting/web/javascript/reference/global_objects/object/index.html b/files/it/conflicting/web/javascript/reference/global_objects/object/index.html new file mode 100644 index 0000000000..568165d0be --- /dev/null +++ b/files/it/conflicting/web/javascript/reference/global_objects/object/index.html @@ -0,0 +1,215 @@ +--- +title: Object.prototype +slug: Web/JavaScript/Reference/Global_Objects/Object/prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Object +translation_of_original: Web/JavaScript/Reference/Global_Objects/Object/prototype +--- +<div>{{JSRef("Global_Objects", "Object")}}</div> + +<h2 id="Summary" name="Summary">Sommario</h2> + +<p>La proprietà <strong><code>Object.prototype</code></strong> rappresenta l'oggetto prototipo di {{jsxref("Global_Objects/Object", "Object")}}.</p> + +<p>{{js_property_attributes(0, 0, 0)}}</p> + +<h2 id="Description" name="Description">Descrizione</h2> + +<p>In JavaScript, tutti gli oggetti sono discendenti di {{jsxref("Global_Objects/Object", "Object")}}; tutti gli oggetti ereditano metodi e proprietà di <code>Object.prototype</code> (tranne nel caso l'oggetto abbia il prototipo uguale a {{jsxref("Global_Objects/null", "null")}}, quindi creati con il metodo {{jsxref("Object.create", "Object.create(null)")}}), anche se questi possono essere sovrascritti. Per esempio, i prototipi degli altri costruttori sovrascrivono la proprietà <code>constructor</code> e forniscono un loro metodo {{jsxref("Object.prototype.toString", "toString()")}}. I cambiamenti al prototipo di Object vengono estesi a tutti gli oggetti, eccetto quelli che sovrascrivono le proprietà e i metodi cambiati.</p> + +<h2 id="Properties" name="Properties">Proprietà</h2> + +<dl> + <dt>{{jsxref("Object.prototype.constructor")}}</dt> + <dd>Specifica la funzione che ha creato l'oggetto a partire dal prototipo.</dd> + <dt>{{jsxref("Object.prototype.__proto__")}} {{non-standard_inline}}</dt> + <dd>È un riferimento all'oggetto usato come prototipo quando l'oggetto è stato istanziato.</dd> + <dt>{{jsxref("Object.prototype.__noSuchMethod__")}} {{non-standard_inline}}</dt> + <dd>Permette di definire una funzione che venga chiamata quando viene chiamato un metodo non definito.</dd> + <dt><s class="obsoleteElement">{{jsxref("Object.prototype.__count__")}} {{obsolete_inline}}</s></dt> + <dd><s class="obsoleteElement">Rappresenta il numero di proprietà persenti in un oggetto, ma è stato rimosso.</s></dd> + <dt><s class="obsoleteElement">{{jsxref("Object.prototype.__parent__")}} {{obsolete_inline}}</s></dt> + <dd><s class="obsoleteElement">Rappresenta il contesto di un oggetto, ma è stato rimosso.</s></dd> +</dl> + +<h2 id="Methods" name="Methods">Metodi</h2> + +<dl> + <dt>{{jsxref("Object.prototype.__defineGetter__()")}} {{non-standard_inline}} {{deprecated_inline}}</dt> + <dd>Associa una funzione a una proprietà di un oggetto. Quando si tenta di leggere il valore di tale proprietà, viene eseguita la funzione e restituito il valore che restituisce.</dd> + <dt>{{jsxref("Object.prototype.__defineSetter__()")}} {{non-standard_inline}} {{deprecated_inline}}</dt> + <dd>Associa una funzione a una proprietà di un oggetto. Quando si tenta di cambiare il valore di tale proprietà, viene eseguita la funzione.</dd> + <dt>{{jsxref("Object.prototype.__lookupGetter__()")}} {{non-standard_inline}} {{deprecated_inline}}</dt> + <dd>Restituisce la funzione definita tramite {{jsxref("Object.prototype.defineGetter", "__defineGetter__()")}}.</dd> + <dt>{{jsxref("Object.prototype.__lookupSetter__()")}} {{non-standard_inline}} {{deprecated_inline}}</dt> + <dd>Restituisce la funzione definita tramite {{jsxref("Object.prototype.defineSetter", "__defineSetter__()")}}.</dd> + <dt>{{jsxref("Object.prototype.hasOwnProperty()")}}</dt> + <dd>Determina se l'oggetto contiene direttamente una proprietà (non ereditata tramite il prototipo).</dd> + <dt>{{jsxref("Object.prototype.isPrototypeOf()")}}</dt> + <dd>Determina se un oggetto fa parte della catena dei prototipi dell'oggetto sul quale è richiamato questo metodo.</dd> + <dt>{{jsxref("Object.prototype.propertyIsEnumerable()")}}</dt> + <dd>Determina se l'<a href="/it/docs/ECMAScript_DontEnum_attribute" title="ECMAScript_DontEnum_attribute">attributo DontEnum di ECMAScript</a> interno è presente.</dd> + <dt>{{jsxref("Object.prototype.toSource()")}} {{non-standard_inline}}</dt> + <dd>Restituisce una stringa contenente il codice sorgente di un oggetto rappresentante l'oggetto sul quale questo metodo viene richiamato; puoi usare questo valore per creare un nuovo oggetto.</dd> + <dt>{{jsxref("Object.prototype.toLocaleString()")}}</dt> + <dd>Richiama {{jsxref("Object.prototype.toString", "toString()")}}.</dd> + <dt>{{jsxref("Object.prototype.toString()")}}</dt> + <dd>Restituisce la rappresentazione dell'oggetto sotto forma di stringa.</dd> + <dt>{{jsxref("Object.prototype.unwatch()")}} {{non-standard_inline}}</dt> + <dd>Termina di osservare i cambiamenti di una proprietà dell'oggetto.</dd> + <dt>{{jsxref("Object.prototype.valueOf()")}}</dt> + <dd>Ritorna il valore primitivo dell'oggetto.</dd> + <dt>{{jsxref("Object.prototype.watch()")}} {{non-standard_inline}}</dt> + <dd>Inizia a osservare i cambiamenti di una proprietà di un oggetto.</dd> + <dt><s class="obsoleteElement">{{jsxref("Object.prototype.eval()")}} {{obsolete_inline}}</s></dt> + <dd><s class="obsoleteElement">Esegue una stringa di codice JavaScript nel contesto dell'oggetto, ma è stato rimosso.</s></dd> +</dl> + +<h2 id="Examples" name="Examples">Esempi</h2> + +<p>Siccome in JavaScript gli oggetti non sono sub-classabili in modo "standard", il prototipo è una soluzione utile per creare un oggetto che funzioni da "classe di base" che contenga dei metodi comuni a più oggetti. Per esempio:</p> + +<pre class="brush: js">var Persona = function() { + this.saParlare = true; +}; + +Persona.prototype.saluta = function() { + if (this.saParlare) { + console.log('Ciao, mi chiamo ' + this.nome); + } +}; + +var Dipendente = function(nome, titolo) { + Persona.call(this); + this.nome = nome; + this.titolo = titolo; +}; + +Dipendente.prototype = Object.create(Persona.prototype); +Dipendente.prototype.constructor = Dipendente; + +Dipendente.prototype.saluta = function() { + if (this.saParlare) { + console.log('Ciao mi chiamo ' + this.nome + ' e lavoro come ' + this.titolo); + } +}; + +var Cliente = function(nome) { + Persona.call(this); + this.nome = nome; +}; + +Cliente.prototype = Object.create(Persona.prototype); +Cliente.prototype.constructor = Cliente; + +var Mimo = function(nome) { + Persona.call(this); + this.nome = nome; + this.saParlare = false; +}; + +Mimo.prototype = Object.create(Persona.prototype); +Mimo.prototype.constructor = Mimo; + +var bob = new Dipendente('Bob', 'Architetto'); +var joe = new Cliente('Joe'); +var rg = new Dipendente('Red Green', 'Tuttofare'); +var mike = new Cliente('Mike'); +var mime = new Mimo('Mimo'); +bob.saluta(); +joe.saluta(); +rg.saluta(); +mike.saluta(); +mime.saluta(); +</pre> + +<p>Stamperà:</p> + +<pre>Ciao, mi chiamo Bob e lavoro come Architetto +Ciao, mi chiamo Joe +Ciao, mi chiamo Red Green, e lavoro come Tuttofare +Ciao, mi chiamo Mike</pre> + +<h2 id="Specifications" name="Specifications">Specifiche</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specifica</th> + <th scope="col">Stato</th> + <th scope="col">Commenti</th> + </tr> + <tr> + <td>ECMAScript 1st Edition. Implemented in JavaScript 1.0.</td> + <td>Standard</td> + <td>Definizione iniziale.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.2.3.1', 'Object.prototype')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-object.prototype', 'Object.prototype')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">Compatibilità con i browser</h2> + +<div>{{CompatibilityTable}}</div> + +<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> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/it/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript">Introduzione alla programmazione JavaScript orientata agli oggetti</a></li> +</ul> diff --git a/files/it/conflicting/web/javascript/reference/global_objects/string/index.html b/files/it/conflicting/web/javascript/reference/global_objects/string/index.html new file mode 100644 index 0000000000..c83cec2a54 --- /dev/null +++ b/files/it/conflicting/web/javascript/reference/global_objects/string/index.html @@ -0,0 +1,179 @@ +--- +title: String.prototype +slug: Web/JavaScript/Reference/Global_Objects/String/prototype +translation_of: Web/JavaScript/Reference/Global_Objects/String +translation_of_original: Web/JavaScript/Reference/Global_Objects/String/prototype +--- +<div>{{JSRef}}</div> + +<p>La proprietà <strong><code>String.prototype</code></strong>rappresenta l'oggetto prototipo {{jsxref("String")}}.</p> + +<div>{{js_property_attributes(0, 0, 0)}}</div> + +<h2 id="Description">Description</h2> + +<p>Tutte le istanze {{jsxref("String")}} ereditano da <code>String.prototype</code> . Le modifiche all'oggetto prototipo <code>String</code> vengono propagate a tutte le istanze {{jsxref("String")}}.</p> + +<h2 id="Properties">Properties</h2> + +<dl> + <dt><code>String.prototype.constructor</code></dt> + <dd>Specifica la funzione che crea il prototipo di un oggetto.</dd> + <dt>{{jsxref("String.prototype.length")}}</dt> + <dd>Riflette la lunghezza della stringa.</dd> + <dt><code><em>N</em></code></dt> + <dd>Utilizzato per accedere al carattere in <em>N</em> posizione in cui <em>N</em> è un numero intero positivo compreso tra 0 e uno inferiore al valore della {{jsxref("String.length", "length")}}. Queste proprietà sono di sola lettura.</dd> +</dl> + +<h2 id="Metodi">Metodi</h2> + +<h3 id="Metodi_non_correlati_HTML">Metodi non correlati HTML</h3> + +<dl> + <dt>{{jsxref("String.prototype.charAt()")}}</dt> + <dd>Restituisce il carattere (esattamente un'unità di codice UTF-16) all'indice specificato</dd> + <dt>{{jsxref("String.prototype.charCodeAt()")}}</dt> + <dd>Restituisce un numero che corrisponde al valore dell'unità di codice UTF-16 nell'indice specificato.</dd> + <dt>{{jsxref("String.prototype.codePointAt()")}}</dt> + <dd>Restituisce un numero intero non negativo <strong>Numero</strong> che è il valore del punto di codice codificato UTF-16 che inizia con l'indice specificato.</dd> + <dt>{{jsxref("String.prototype.concat()")}}</dt> + <dd>Combina il testo di due stringhe e restituisce una nuova stringa.</dd> + <dt>{{jsxref("String.prototype.includes()")}}</dt> + <dd>Determina se una stringa può essere trovata all'interno di un'altra stringa.</dd> + <dt>{{jsxref("String.prototype.endsWith()")}}</dt> + <dd>Determina se una stringa termina con i caratteri di un'altra stringa.</dd> + <dt>{{jsxref("String.prototype.indexOf()")}}</dt> + <dd>Restituisce l'indice all'interno dell'oggetto {{jsxref("String")}} chiamante della prima occorrenza del valore specificato o -1 se non trovato.</dd> + <dt>{{jsxref("String.prototype.lastIndexOf()")}}</dt> + <dd>Restituisce l'indice all'interno dell'oggetto {{jsxref("String")}} chiamante della prima occorrenza del valore specificato o -1 se non trovato.</dd> + <dt>{{jsxref("String.prototype.localeCompare()")}}</dt> + <dd>Restituisce un numero che indica se una stringa di riferimento viene prima o dopo o è uguale alla stringa specificata in ordine di ordinamento.</dd> + <dt>{{jsxref("String.prototype.match()")}}</dt> + <dd>Utilizzato per abbinare un'espressione regolare a una stringa.</dd> + <dt>{{jsxref("String.prototype.normalize()")}}</dt> + <dd>Restituisce il modulo di normalizzazione Unicode del valore della stringa chiamante.</dd> + <dt>{{jsxref("String.prototype.padEnd()")}}</dt> + <dd>Riempie la stringa corrente dalla fine con una determinata stringa per creare una nuova stringa di una determinata lunghezza.</dd> + <dt>{{jsxref("String.prototype.padStart()")}}</dt> + <dd>Riempie la stringa corrente dall'inizio con una determinata stringa per creare una nuova stringa da una determinata lunghezza.</dd> + <dt><s class="obsoleteElement">{{jsxref("String.prototype.quote()")}} {{obsolete_inline}}</s></dt> + <dd><s class="obsoleteElement">Avvolge la stringa tra virgolette ("<code>"</code>").</s></dd> + <dt>{{jsxref("String.prototype.repeat()")}}</dt> + <dd>Restituisce una stringa composta da elementi dell'oggetto ripetuti i tempi indicati.</dd> + <dt>{{jsxref("String.prototype.replace()")}}</dt> + <dd>Utilizzato per trovare una corrispondenza tra un'espressione regolare e una stringa e per sostituire la sottostringa con corrispondenza con una nuova sottostringa.</dd> + <dt>{{jsxref("String.prototype.search()")}}</dt> + <dd>Esegue la ricerca di una corrispondenza tra un'espressione regolare e una stringa specificata.</dd> + <dt>{{jsxref("String.prototype.slice()")}}</dt> + <dd>Estrae una sezione di una stringa e restituisce una nuova stringa.</dd> + <dt>{{jsxref("String.prototype.split()")}}</dt> + <dd>Divide un oggetto {{jsxref("Global_Objects/String", "String")}} in una matrice di stringhe separando la stringa in sottostringhe.</dd> + <dt>{{jsxref("String.prototype.startsWith()")}}</dt> + <dd>Determina se una stringa inizia con i caratteri di un'altra stringa.</dd> + <dt>{{jsxref("String.prototype.substr()")}} {{deprecated_inline}}</dt> + <dd>Restituisce i caratteri in una stringa che inizia nella posizione specificata attraverso il numero specificato di caratteri.</dd> + <dt>{{jsxref("String.prototype.substring()")}}</dt> + <dd>Restituisce i caratteri in una stringa tra due indici nella stringa.</dd> + <dt>{{jsxref("String.prototype.toLocaleLowerCase()")}}</dt> + <dd>I caratteri all'interno di una stringa vengono convertiti in minuscolo rispettando le impostazioni locali correnti. Per la maggior parte delle lingue, questo restituirà lo stesso di {{jsxref("String.prototype.toLowerCase()", "toLowerCase()")}}.</dd> + <dt>{{jsxref("String.prototype.toLocaleUpperCase()")}}</dt> + <dd>I caratteri all'interno di una stringa vengono convertiti in maiuscolo rispettando le impostazioni locali correnti. Per la maggior parte delle lingue, ciò restituirà lo stesso di {{jsxref("String.prototype.toUpperCase()", "toUpperCase()")}}.</dd> + <dt>{{jsxref("String.prototype.toLowerCase()")}}</dt> + <dd>Restituisce il valore della stringa chiamante convertito in minuscolo.</dd> + <dt>{{jsxref("String.prototype.toSource()")}} {{non-standard_inline}}</dt> + <dd>Restituisce un oggetto letterale che rappresenta l'oggetto specificato; puoi usare questo valore per creare un nuovo oggetto. Sostituisce il metodo {{jsxref("Object.prototype.toSource()")}} method.</dd> + <dt>{{jsxref("String.prototype.toString()")}}</dt> + <dd>Restituisce una stringa che rappresenta l'oggetto specificato. Sostituisce il metodo {{jsxref("Object.prototype.toString()")}} .</dd> + <dt>{{jsxref("String.prototype.toUpperCase()")}}</dt> + <dd>Restituisce il valore della stringa chiamante convertito in maiuscolo.</dd> + <dt>{{jsxref("String.prototype.trim()")}}</dt> + <dd>Taglia gli spazi bianchi all'inizio e alla fine della stringa. Parte dello standard ECMAScript 5.</dd> + <dt>{{jsxref("String.prototype.trimStart()")}}<br> + {{jsxref("String.prototype.trimLeft()")}}</dt> + <dd>Taglia gli spazi bianchi dall'inizio della stringa.</dd> + <dt>{{jsxref("String.prototype.trimEnd()")}}<br> + {{jsxref("String.prototype.trimRight()")}}</dt> + <dd>Taglia gli spazi bianchi dalla fine della stringa.</dd> + <dt>{{jsxref("String.prototype.valueOf()")}}</dt> + <dd>Restituisce il valore primitivo dell'oggetto specificato. Sostituisce il metodo {{jsxref("Object.prototype.valueOf()")}}.</dd> + <dt>{{jsxref("String.prototype.@@iterator()", "String.prototype[@@iterator]()")}}</dt> + <dd>Restituisce un nuovo oggetto <code>Iterator</code> che itera sopra i punti di codice di un valore String, restituendo ogni punto di codice come valore String.</dd> +</dl> + +<h3 id="HTML_metodi_wrapper_(involucro)">HTML metodi wrapper (involucro)</h3> + +<p>Questi metodi sono di uso limitato, in quanto forniscono solo un sottoinsieme dei tag e degli attributi HTML disponibili.</p> + +<dl> + <dt>{{jsxref("String.prototype.anchor()")}} {{deprecated_inline}}</dt> + <dd>{{htmlattrxref("name", "a", "<a name=\"name\">")}} (hypertext target)</dd> + <dt>{{jsxref("String.prototype.big()")}} {{deprecated_inline}}</dt> + <dd>{{HTMLElement("big")}}</dd> + <dt>{{jsxref("String.prototype.blink()")}} {{deprecated_inline}}</dt> + <dd>{{HTMLElement("blink")}}</dd> + <dt>{{jsxref("String.prototype.bold()")}} {{deprecated_inline}}</dt> + <dd>{{HTMLElement("b")}}</dd> + <dt>{{jsxref("String.prototype.fixed()")}} {{deprecated_inline}}</dt> + <dd>{{HTMLElement("tt")}}</dd> + <dt>{{jsxref("String.prototype.fontcolor()")}} {{deprecated_inline}}</dt> + <dd>{{htmlattrxref("color", "font", "<font color=\"color\">")}}</dd> + <dt>{{jsxref("String.prototype.fontsize()")}} {{deprecated_inline}}</dt> + <dd>{{htmlattrxref("size", "font", "<font size=\"size\">")}}</dd> + <dt>{{jsxref("String.prototype.italics()")}} {{deprecated_inline}}</dt> + <dd>{{HTMLElement("i")}}</dd> + <dt>{{jsxref("String.prototype.link()")}} {{deprecated_inline}}</dt> + <dd>{{htmlattrxref("href", "a", "<a href=\"url\">")}} (link to URL)</dd> + <dt>{{jsxref("String.prototype.small()")}} {{deprecated_inline}}</dt> + <dd>{{HTMLElement("small")}}</dd> + <dt>{{jsxref("String.prototype.strike()")}} {{deprecated_inline}}</dt> + <dd>{{HTMLElement("strike")}}</dd> + <dt>{{jsxref("String.prototype.sub()")}} {{deprecated_inline}}</dt> + <dd>{{HTMLElement("sub")}}</dd> + <dt>{{jsxref("String.prototype.sup()")}} {{deprecated_inline}}</dt> + <dd>{{HTMLElement("sup")}}</dd> +</dl> + +<h2 id="Specificazioni">Specificazioni</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specificazioni</th> + <th scope="col">Stato</th> + <th scope="col">Commento</th> + </tr> + <tr> + <td>{{SpecName('ES1')}}</td> + <td>{{Spec2('ES1')}}</td> + <td>Definizione iniziale.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-15.5.3.1', 'String.prototype')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-string.prototype', 'String.prototype')}}</td> + <td>{{Spec2('ES6')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-string.prototype', 'String.prototype')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilità_con_il_browser">Compatibilità con il browser</h2> + +<p class="hidden"> tabella di compatibilità in questa pagina è generata da dati strutturati. Se desideri contribuire ai dati, consulta <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> e inviaci una richiesta di pull.</p> + +<p>{{Compat("javascript.builtins.String.prototype")}}</p> + +<h2 id="Guarda_anche">Guarda anche</h2> + +<ul> + <li>{{jsxref("String")}}</li> + <li>{{jsxref("Function.prototype")}}</li> +</ul> diff --git a/files/it/conflicting/web/javascript/reference/operators/index.html b/files/it/conflicting/web/javascript/reference/operators/index.html new file mode 100644 index 0000000000..e49fe045ae --- /dev/null +++ b/files/it/conflicting/web/javascript/reference/operators/index.html @@ -0,0 +1,292 @@ +--- +title: Operatori Aritmetici +slug: Web/JavaScript/Reference/Operators/Operatori_Aritmetici +tags: + - JavaScript + - Operatori + - Operatori Aritmetici +translation_of: Web/JavaScript/Reference/Operators +translation_of_original: Web/JavaScript/Reference/Operators/Arithmetic_Operators +--- +<div>{{jsSidebar("Operators")}}</div> + +<div>Gli <strong>operatori aritmetici</strong> lavorano su operandi numerici (sia letterali che variabili) e ritornano un singolo valore numerico. Gli operatori aritmetici standard sono l'addizione (+), la sottrazione (-), la moltiplicazione (*) e la divisione (/).</div> + +<h2 id="Addizione_()"><a name="Addition">Addizione (+)</a></h2> + +<p>L'operazione di addizione produce la somma di operandi numerici o la concatenzione di stringhe.</p> + +<h3 id="Sintassi">Sintassi</h3> + +<pre class="syntaxbox"><strong>Operatore:</strong> x + y +</pre> + +<h3 id="Esempi">Esempi</h3> + +<pre class="brush: js">// Numero + Numero -> addizione +1 + 2 // 3 + +// Booleano + Numero -> addizione +true + 1 // 2 + +// Booleano + Booleano -> additione +false + false // 0 + +// Numero + Stringa -> concatenazione +5 + "foo" // "5foo" + +// Stringa + Booleano -> concatenazione +"foo" + false // "foofalse" + +// Stringa + Stringa -> concatenazione +"foo" + "bar" // "foobar" +</pre> + +<h2 id="Sottrazione_(-)"><a name="Subtraction">Sottrazione (-)</a></h2> + +<p>L'operatore di sottrazione fa la sottrazione dei due operandi e produce la loro differenza.</p> + +<h3 id="Sintassi_2">Sintassi</h3> + +<pre class="syntaxbox"><strong>Operatore:</strong> x - y +</pre> + +<h3 id="Esempi_2">Esempi</h3> + +<pre class="brush: js">5 - 3 // 2 +3 - 5 // -2 +"foo" - 3 // NaN</pre> + +<h2 id="Divisione_()"><a name="Division">Divisione (/)</a></h2> + +<p>L'operatore di divisione produce il quoziente dei suoi operandi dove l'operando di sinistra è il dividendo e l'operando di destra è il divisore.</p> + +<h3 id="Sintassi_3">Sintassi</h3> + +<pre class="syntaxbox"><strong>Operatore:</strong> x / y +</pre> + +<h3 id="Esempi_3">Esempi</h3> + +<pre class="brush: js">1 / 2 // restituisce 0.5 in JavaScript +1 / 2 // restituisce 0 in Java +// (nessuno degli operandi è un numero in virgola mobile esplicito) + +1.0 / 2.0 // restituisce 0.5 in both JavaScript and Java + +2.0 / 0 // restituisce Infinity in JavaScript +2.0 / 0.0 // restituisce Infinity too +2.0 / -0.0 // restituisce -Infinity in JavaScript</pre> + +<h2 id="Moltiplicazione_(*)"><a name="Multiplication">Moltiplicazione (*)</a></h2> + +<p>The multiplication operator produces the product of the operands.</p> + +<h3 id="Sintassi_4">Sintassi</h3> + +<pre class="syntaxbox"><strong>Operatore:</strong> x * y +</pre> + +<h3 id="Esempi_4">Esempi</h3> + +<pre class="brush: js">2 * 2 // 4 +-2 * 2 // -4 +Infinity * 0 // NaN +Infinity * Infinity // Infinity +"foo" * 2 // NaN +</pre> + +<h2 id="Resto_()"><a name="Remainder">Resto (%)</a></h2> + +<p>L'operatore Resto o Modulo restituisce il “resto“ rimasto quando un operando viene diviso per un secondo operando. Calcola il resto della divisione fra il primo e il secondo operando. Porta sempre il segno del dividendo.</p> + +<h3 id="Sintassi_5">Sintassi</h3> + +<pre class="syntaxbox"><strong>Operatore:</strong> var1 % var2 +</pre> + +<h3 id="Esempi_5">Esempi</h3> + +<pre class="brush: js">12 % 5 // 2 +-1 % 2 // -1 +NaN % 2 // NaN +1 % 2 // 1 +2 % 3 // 2 +-4 % 2 // -0 +</pre> + +<h2 id="Esponente_(**)"><a name="Exponentiation">Esponente (**)</a></h2> + +<p><strong>L'operatore Esponente o esponenziale in JavaScript. </strong>Una delle funzionalità di questa versione è l'operatore di esponenziazione. Esponente restituisce il risultato dell'elevamento a potenza dal primo operando al secondo. Cioè <code>var1</code> <code>var2</code> , <code>var2.</code> <code>var1</code>e <code>var2</code> sono variabili. L'operatore Esponente ha ragione associativa. <code>a ** b ** c</code> equivale a <code>a ** (b ** c)</code>.</p> + +<h3 id="Sintassi_6">Sintassi</h3> + +<pre class="syntaxbox"><strong>Operatore:</strong> var1 ** var2 +</pre> + +<h3 id="Note">Note</h3> + +<p>Nella maggior parte dei linguaggi come PHP e Python e altri che usano l'operatore Esponente (**), ha precedenza rispetto agli altri operatori unari come + e -, salvo in alcune eccezioni. Ad esempio, in Bash l'operatore ** ha una minor importanza rispetto agli operatori unari. In JavaScript, è impossibile scrivere un'espressione Esponente ambigua, ovvero non è possibile inserire un operatore unario ( <code>+/-/~/!/delete/void/typeof</code> ) immediatamente prima del numero di base. Il calcolo della potenza può essere espresso più sinteticamente usando la notazione infissa. Simile ad altri linguaggi come Python o F#, <code>**</code> è usato per indicare l'operatore. </p> + +<pre class="brush: js">-2 ** 2 // equals 4 in ES2016 or in Bash, equals -4 in other languages.</pre> + +<p>Accetta base sul lato sinistro ed esponente sul lato destro, rispettivamente.</p> + +<pre class="brush: js">let value = 5; value **= 2; // value: 25 +</pre> + +<h3 id="Esempi_6">Esempi</h3> + +<pre class="brush: js">2 ** 3 // 8 +3 ** 2 // 9 +3 ** 2.5 // 15.588457268119896 +10 ** -1 // 0.1 +NaN ** 2 // NaN + +2 ** 3 ** 2 // 512 +2 ** (3 ** 2) // 512 +(2 ** 3) ** 2 // 64 + +var a = 3; +var b = a ** 3; +alert("3x3x3 is = " + b); // 27 +</pre> + +<p>Per invertire il segno del risultato di un'espressione di Esponente:</p> + +<pre><code>-(2 ** 2) // -4</code> +</pre> + +<p>Per forzare la base di un'espressione di Esponente ad essere un numero negativo:</p> + +<pre><code>(-2) ** 2 // 4 </code></pre> + +<h2 id="Incremento_()"><a name="Increment">Incremento (++)</a></h2> + +<p>L'operatore di incremento incrementa (aggiunge uno a) il suo operando e restituisce un valore.</p> + +<ul> + <li>Se usato in post posizione, con operatore dopo operando (ad esempio, x ++), restituisce il valore prima di incrementare.</li> + <li>Se usato come prefisso quindi prima dell'operando (ad esempio, ++ x), restituisce il valore dopo l'incremento.</li> +</ul> + +<h3 id="Sintassi_7">Sintassi</h3> + +<pre class="syntaxbox"><strong>Operatore:</strong> x++ or ++x +</pre> + +<h3 id="Esempi_7">Esempi</h3> + +<pre class="brush: js">// Postfix // post posizione +var x = 3; +y = x++; // y = 3, x = 4 + +// Prefix // Prefisso +var a = 2; +b = ++a; // a = 3, b = 3 +</pre> + +<h2 id="Decremento_(--)"><a name="Decrement">Decremento (--)</a></h2> + +<p>L'operatore decrementa decrementa (sottrae uno da) il suo operando e restituisce un valore.</p> + +<ul> + <li>Se usato in post posizione (ad esempio x--), restituisce il valore prima di decrementare.</li> + <li>Se usato come prefisso (ad esempio, --x), restituisce il valore dopo la decrementazione.</li> +</ul> + +<h3 id="Sintassi_8">Sintassi</h3> + +<pre class="syntaxbox"><strong>Operatore:</strong> x-- or --x +</pre> + +<h3 id="Esempi_8">Esempi</h3> + +<pre class="brush: js">// Postfix // post posizione +var x = 3; +y = x--; // y = 3, x = 2 + +// Prefix // Prefisso +var a = 2; +b = --a; // a = 1, b = 1 +</pre> + +<h2 id="Negazione_unaria_(-)"><a name="Unary_negation">Negazione unaria (-)</a></h2> + +<p>L'operatore di negazione unario precede il suo operando e lo nega.</p> + +<h3 id="Sintassi_9">Sintassi</h3> + +<pre class="syntaxbox"><strong>Operatore:</strong> -x +</pre> + +<h3 id="Esempi_9">Esempi</h3> + +<pre><code>var x = 3; +y = -x; // y = -3, x = 3 + +//</code>L'operatore di negazione unario può convertire numeri diversi in un numero<code> +var x = "4"; +y = -x; // y = -4</code></pre> + +<h2 id="Unario_più_()"><a name="Unary_plus">Unario più</a> (+)</h2> + +<p>L'operatore unario più precede il suo operando e valuta il suo operando, ma tenta di convertirlo in un numero, se non lo è già. Anche se la negazione unaria (-) può anche convertire non numeri, unario è il modo più veloce e preferito per convertire qualcosa in un numero, perché non esegue altre operazioni sul numero. È in grado di convertire rappresentazioni di stringa di numeri interi e float, oltre ai valori non stringa <code>true</code> , <code>false</code> e <code>null</code> . Sono supportati i numeri interi decimali ed esadecimali ("0x" -prefixed). I numeri negativi sono supportati (sebbene non per hex). Se non può analizzare un valore particolare, valuterà in <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN">NaN</a>.</p> + +<h3 id="Sintassi_10">Sintassi</h3> + +<pre class="syntaxbox"><strong>Operatore:</strong> +x +</pre> + +<h3 id="Esempi_10">Esempi</h3> + +<pre><code>+3 // 3 ++'3' // 3 ++true // 1 ++false // 0 ++null // 0 ++function(val){ return val } // NaN</code></pre> + +<h2 id="Specificazioni">Specificazioni</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specificazioni</th> + <th scope="col">Stato</th> + <th scope="col">Commento</th> + </tr> + <tr> + <td>ECMAScript 1st Edition.</td> + <td>Standard</td> + <td>Definizione iniziale.</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-11.3')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td>Definito in diverse sezioni della specifica: <a href="http://www.ecma-international.org/ecma-262/5.1/#sec-11.6">Additive operators</a>, <a href="http://www.ecma-international.org/ecma-262/5.1/#sec-11.5">Multiplicative operators</a>, <a href="http://www.ecma-international.org/ecma-262/5.1/#sec-11.3">Postfix expressions</a>, <a href="http://www.ecma-international.org/ecma-262/5.1/#sec-11.4">Unary operators</a>.</td> + </tr> + <tr> + <td>{{SpecName('ES2015', '#sec-postfix-expressions')}}</td> + <td>{{Spec2('ES2015')}}</td> + <td>Definito in diverse sezioni della specifica: <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-additive-operators">Additive operators</a>, <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-multiplicative-operators">Multiplicative operators</a>, <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-postfix-expressions">Postfix expressions</a>, <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-unary-operators">Unary operators</a>.</td> + </tr> + <tr> + <td>{{SpecName('ES2016', '#sec-postfix-expressions')}}</td> + <td>{{Spec2('ES2016')}}</td> + <td>Aggiunto <a href="https://github.com/rwaldron/exponentiation-operator">Exponentiation operator</a>.</td> + </tr> + </tbody> +</table> + +<h2 id="Compatibilità_con_i_browser">Compatibilità con i browser</h2> + + + +<p>{{Compat("javascript.operators.arithmetic")}}</p> + +<h2 id="Guarda_anche">Guarda anche</h2> + +<ul> + <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators">Assignment operators</a></li> +</ul> |