Advertisement
NubeColectiva

6 Formas de Crear una Función en JavaScript

Mar 9th, 2023
1,113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function miFuncion1(p1, p2) {
  2.     return p1 + p2;
  3. }
  4.  
  5. //console.log(miFuncion1(2,2));
  6.  
  7. var suma = function(p1, p2) {
  8.     return p1 + p2;
  9. }
  10.  
  11. //console.log(suma(3,3));
  12.  
  13. var suma2 = (p1, p2) => {
  14.     return p1 + p2;
  15. }
  16.  
  17. //console.log(suma2(1,1));
  18.  
  19. (function suma3(p1, p2) {
  20.     return p1 + p2;
  21. })(5,5)
  22.  
  23. /*
  24. console.log((function suma3(p1, p2) {
  25.     return p1 + p2;
  26. })(5,5))
  27. */
  28.  
  29. var obj = {
  30.     suma4: function(p1, p2) {
  31.         return p1 + p2;
  32.     }
  33. };
  34.  
  35. //console.log(obj.suma4(10,10));
  36.  
  37. var suma5 = new Function("p1", "p2", "return p1 + p2");
  38.  
  39. console.log(suma5(15,15));
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement