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 128 views
1 answer 134 views
1 answer 114 views
1 answer 132 views
1 answer 166 views
1 answer 145 views
...