Skip to content

Instantly share code, notes, and snippets.

@2rohityadav
Last active August 12, 2018 06:38
Show Gist options
  • Save 2rohityadav/58842de8152a5c48e05123ed3f24b4ea to your computer and use it in GitHub Desktop.
Save 2rohityadav/58842de8152a5c48e05123ed3f24b4ea to your computer and use it in GitHub Desktop.
Imperative vs Declarative
// Imperattive (How - means not have trust that's y we telling how gonna execute things)
var numbers = [3,2,4,5]
var total = 0
for(var i=0; i< numbers.length; i++){
  total += numbers[i]
}
  // Declarative (What - have trust no matter we know will happen exactly what we want)
  var numbers = [3,2,4,5]
  numbers.reduce(function(previous, current){
    return previous + current
  })

+ Declarative benifits

  - Reduce side effects
  - Minimize mutability
  - More readable code
  - Less bugs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment