This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// - - Exported file [calculate.js] - - | |
const add = (a,b)=>{ | |
return a + b | |
} | |
module.exports = add |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// - - - Main File[main.js] - - | |
const add = require('./calculate') //name of the desired file | |
const result = add(2,4) | |
console.log(result); //Output : 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// - - Exported file [calculate.js] - - | |
const add = { | |
result : (a,b)=>{ | |
return a + b | |
} | |
} | |
module.exports = add |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// - - Main file[main.js] - - | |
const add = require('./calculate') | |
const result = add.result(5,8) | |
console.log(result) //Output : 13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// - - Exported file [calculate.js] - - | |
const add = { | |
result : (a,b)=>{ | |
return a + b | |
} | |
} | |
module.exports = add.result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// - - Main file[main.js] - - | |
const add = require('./calculate') | |
const result = add(5,8) | |
console.log(result) //Output : 13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// - - Exported file [calculate.js] - - | |
function Add (){ | |
this.result = (a,b)=>{ | |
return a + b | |
} | |
} | |
module.exports = new Add() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// - - Main file[main.js] - - | |
const add = require('./calculate') | |
const result = add.result(2,1) | |
console.log(result); //Output : 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// - - Exported file [calculate.js] - - | |
const Add = class{ | |
constructor(a,b){ | |
this.a = a; | |
this.b = b; | |
} | |
result(){ | |
return this.a + this.b | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// - - Main file[main.js] - - | |
const add = require('./calculate') | |
const result = new add(2,5) | |
console.log(result.result()); //Output : 7 |
OlderNewer