How to create and use a function inside an object in Node.js

1 Answer

0 votes
const obj = {
    num: 15,
    sum(a, b) {
        return a + b + this.num;
    },
};

console.log(obj.sum(5, 8)); 
 
  
  
  
  
/*
run:
  
28
  
*/

 



answered May 2, 2022 by avibootz

Related questions

1 answer 123 views
1 answer 131 views
1 answer 112 views
1 answer 156 views
1 answer 137 views
1 answer 122 views
...