анонимная функция





js/script.js
  • var fun1 = function() {
  •  document.write('Hello World!<br />');
  • }
  •  
  • var fun2 = function fact(n) {
  •  if(n>1) {
  •   return n * fact(n-1);
  •  }
  •  else {
  •   return 1;
  •  }
  • }
var fun1 = function() {
 document.write('Hello World!
'); } var fun2 = function fact(n) { if(n>1) { return n * fact(n-1); } else { return 1; } }


index.html
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <script src="js/script.js"></script>
  • </head>
  • <body>
  • <script>
  •  fun1();
  •  document.write('factorial of number 5 = ' + fun2(5));
  • </script>
  • </body>
  • </html>
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <script src="js/script.js"></script>
  • </head>
  • <body>
  • <script>
  •  fun1();
  •  document.write('factorial of number 5 = ' + fun2(5));
  • </script>
  • </body>
  • </html>