Skip to content

Instantly share code, notes, and snippets.

@sagarPakhrin
Created November 23, 2019 16:23
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 sagarPakhrin/474a65dae0cce0a241a950aa697cc9b3 to your computer and use it in GitHub Desktop.
Save sagarPakhrin/474a65dae0cce0a241a950aa697cc9b3 to your computer and use it in GitHub Desktop.

Functional Programming with React

In JS Functions can represent data in your applications

const log = message=>console.log(message)

Since Functions are variables we can add them to objects

const obj = {
		message: "They can be added to objects like variables",
		log
}

Functions can also be added to arrays

const messages = [
		"They can also be added to arrays",
		message=>console.log(message),
		"like variables",
		message=>console.log(message)
]
message[1](message[0]) // they can be inserted into arrays 
message[3](message[2]) // like variables

They can also be sent to functions as arguments

const insideFn = logger => logger("They can me sent to other functions as arguments")
insideFn(message=>cnosole.log(message))
// They can me sent to other functions as arguments 

They can also be returned from other functions just like variables

let createScream = function(logger){
		return function(message){
				logger(message.toUpperCase() + "!!!")
		}
}

const scream = createScream(message=>console.log(message))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment