Skip to content

Instantly share code, notes, and snippets.

@dleitee
Created March 14, 2017 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dleitee/d91692af515e197fcd93dbc4ceeaca06 to your computer and use it in GitHub Desktop.
Save dleitee/d91692af515e197fcd93dbc4ceeaca06 to your computer and use it in GitHub Desktop.
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