What is functional programming? and why? Source: https://www.youtube.com/watch?v=e-5obm1G_FY A programming paradigm a coding style a mindset a sexy, buzz-wordy trend safer, easier to debug/maintain established community Not functional: var name = “Anjana”; var greeting = “Hi, I’m ”; console.log(greeting + name); Output : “Hi, I’m Anjana” Functional: function greet(name) { return “Hi, I’m ” + name; } greet(“Anjana”); Output: “Hi, I’m Anjana” Avoid side effects use “pure” functions Not pure: var name = “Anjana”; function greet() { console.log(“Hi, I’m ” + name); } Pure: function greet(name) { return “Hi, I’m ” + name; } Use higher-order functions functions can be inputs/outputs function makeAdjectifier(adjective) { return function (string...
Comments
Post a Comment