Last active
March 25, 2021 01:22
-
-
Save ludofleury/c1a9a93e74de4dd645351d04782b2321 to your computer and use it in GitHub Desktop.
Attribute & Method vs Variable & Function
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
//////////// Object oriented programming | |
console.log('Calculator:'); | |
let calculator = { | |
// attribute "result" of calculator object | |
result: 0, | |
// method "add()" of calculator object | |
add: function (number) { | |
this.result += number; | |
}, | |
} | |
calculator.add(2) | |
calculator.add(5) | |
console.log(calculator.result); | |
////////////// Functionnal programming | |
console.log('Function:'); | |
// function "add()"" | |
function add(number1, number2) { | |
return number1 + number2; | |
} | |
// variable "result" | |
let result = 0; | |
result = add(result, 2) | |
result = add(result, 5); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment