'Il metodo valueOf ()
'valueOf() restituisce un numero come un numero. 'Esempio 'var x = 123; 'x.valueOf(); // returns 123 from variable x '(123).valueOf(); // returns 123 from literal 123 '(100 + 23).valueOf(); // returns 123 from expression 100 + 23 'In JavaScript, un numero puo' essere un valore primitivo (typeof = number) o un oggetto (typeof = object). 'Il valueOf()metodo e' utilizzato internamente in JavaScript per convertire oggetti numerici in valori primitivi. 'Non c'e' motivo di usarlo nel tuo codice. 'Tutti i tipi di dati JavaScript hanno valueOf()un toString()metodo e un metodo. https://www.w3schools.com/js/tryit.asp?filename=tryjs_number_valueof <!DOCTYPE html> <html> <body> <h2>JavaScript Number Methods</h2> <p>The valueOf() method returns a number as a number:</p> <p id="demo"></p> <script> var x = 123; document.getElementById("demo").innerHTML = x.valueOf() + "<br>" + (123).valueOf() + "<br>" + (100 + 23).valueOf(); </script> </body> </html> |