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 117 views
1 answer 123 views
1 answer 103 views
1 answer 149 views
1 answer 130 views
1 answer 110 views
...