Advertisement
fcamuso

Javascript Lezione 29

Mar 26th, 2022
1,603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <html>
  3. <head>
  4.     <title>espressioni, precedenze ed associatività</title>
  5.  </head>
  6.  
  7. <body>
  8.  
  9.   <script type="text/javascript">
  10.     let br = "<br>";
  11.    
  12.     //operatori di assegnamento
  13.     let x = 49.99;
  14.     x += 5; //x = x+5
  15.     x -= 5; //x = x-5;
  16.     x*=2; // x = x*2;
  17.     x/=2; // x = x / 2;
  18.     document.write( x + br);
  19.    
  20.     x = 4;
  21.     let y = 3;
  22.     x += (6 - y) * (x - y);
  23.     document.write( x + br); //7
  24.    
  25.     //pre e post incremento/decremento
  26.     x = 0;
  27.     y = ++x; //pre incremento: prima si incrementa x e poi la si usa
  28.     document.write( y + br); //y==1, x==1
  29.  
  30.     x = 0;
  31.     y = x--; //post decremento: prima si usa la x e poi la si incrementa
  32.     document.write( y + br); //y==0, x==-1
  33.  
  34.     let nome="Alessandro", conta=0;
  35.     while (conta<nome.length)
  36.     {
  37.       document.write( nome.charAt(conta) + br);
  38.       conta++;
  39.     }
  40.  
  41.     //operatore virgola
  42.     for (let i = 0, j = 9; i <= j; i++, j--)
  43.     {document.write(i + (j + " ") );}
  44.     document.write(br);
  45.  
  46.    
  47.  </script>
  48.  
  49. </body>
  50. </html>
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement