Created
March 14, 2017 01:43
-
-
Save dleitee/d91692af515e197fcd93dbc4ceeaca06 to your computer and use it in GitHub Desktop.
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
const account = { | |
balance: 1000, | |
bank: '', | |
number: '', | |
} | |
const deposit = (account, value) => { | |
const newAccount = account | |
newAccount.balance = account.balance + value | |
return newAccount | |
} | |
const newAccount1 = deposit(account, 1000) | |
console.log(account, newAccount1) // will print account with balance = 2000 and new account with balance = 2000 | |
const newAccount2 = deposit(account, 1000) | |
console.log(account, newAccount2) // will print account with balance = 3000 and new account with balance = 3000 | |
const newAccount3 = deposit(account, 1000) // no matter what happens, always will returns an account with balance = 2000 | |
console.log(account, newAccount3) // will print account with balance = 4000 and new account with balance = 4000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment