Skip to content

Instantly share code, notes, and snippets.

@amowu
Created January 15, 2017 09:02
Show Gist options
  • Select an option

  • Save amowu/4d6fa47f0535d964c3f819f73e2ed073 to your computer and use it in GitHub Desktop.

Select an option

Save amowu/4d6fa47f0535d964c3f819f73e2ed073 to your computer and use it in GitHub Desktop.
Functional Programming

Master the JavaScript Interview: What is Functional Programming?

Functional Programming

  • Pure functions
    • Given the same inputs, always returns the same output, and
    • Has no side-effects
  • Function composition
    • composition over imperative flow control
  • Avoid shared state
    • Pure functions instead of shared state & side effects
  • Avoid mutating state
    • Immutability over mutable data
  • Avoid side effects
    • Modifying any external variable or object property (e.g., a global variable, or a variable in the parent function scope chain)
    • Logging to the console
    • Writing to the screen
    • Writing to a file
    • Writing to the network
    • Triggering any external process
    • Calling any other functions with side-effects
  • higher order function
    • Lots of generic, reusable utilities that use higher order functions to act on many data types instead of methods that only operate on their colocated data
    • Containers, Functors, Lists, and Streams
    • Containers & higher order functions over ad-hoc polymorphism
  • Declarative vs Imperative
    • Imperative
      • the flow control: How to do things.
      • A statement is a piece of code which performs some action. Examples of commonly used statements include for, if, switch, throw, etc…
    • Declarative
      • describing the data flow: What to do.
      • An expression is a piece of code which evaluates to some value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment