Skip to content

Instantly share code, notes, and snippets.

View SarveshKadam's full-sized avatar
🏠
Working from home

Sarvesh Kadam SarveshKadam

🏠
Working from home
View GitHub Profile
// - - Exported file [calculate.js] - - 
const add = (a,b)=>{
 return a + b
}
module.exports = add
// - - - Main File[main.js] - - 
const add = require('./calculate') //name of the desired file
const result = add(2,4)
console.log(result); //Output : 6
// - - Exported file [calculate.js] - - 
const add = {
 result : (a,b)=>{
 return a + b
 }
}
module.exports = add
// - - Main file[main.js] - - 
const add = require('./calculate')
const result = add.result(5,8)
console.log(result) //Output : 13
// - - Exported file [calculate.js] - - 
const add = {
 result : (a,b)=>{
 return a + b
 }
}
module.exports = add.result
// - - Main file[main.js] - - 
const add = require('./calculate')
const result = add(5,8)
console.log(result) //Output : 13
// - - Exported file [calculate.js] - - 
function Add (){
this.result = (a,b)=>{
return a + b
}
}
module.exports = new Add()
// - - Main file[main.js] - - 
const add = require('./calculate')
const result = add.result(2,1)
console.log(result); //Output : 3
// - - Exported file [calculate.js] - - 
const Add = class{
  constructor(a,b){
  this.a = a;
  this.b = b;
  }
result(){
  return this.a + this.b
  }
// - - Main file[main.js] - - 
const add = require('./calculate')
const result = new add(2,5)
console.log(result.result()); //Output : 7