SlideShare a Scribd company logo
Functional JavaScript
Follow me twitter: @djidja8
This deck online with live code editing: functional-js
JavaScript Overview
 Type System
 Primitive Values
 Objects
 Inheritance
 Functions
 Closures
JavaScript Overview – Type System
JavaScript has dynamic and loosely typed type system with two main types:
Primitive (value) types:
 number
 string
 boolean
 null
 Undefined
Object (reference) types:
 Object
 Function
 Array
 Date
 RegExp
 *Wrappers for primitives: Boolean, Number, String
JavaScript Overview – Type System
@vijayan blog: JavaScript Type Model
JavaScript Overview – Type System
JavaScript Overview – Primitive Values
JavaScript Overview - Objects
JavaScript Overview - Objects
JavaScript Overview - Inheritance
JavaScript supports a prototype-based inheritance.
Inheritance is performed by creating new objects directly, based on existing ones, existing object is assigned as the
prototype of the new object and then inherited behavior can be changed or new behavior can be added to the new
object.
 The prototype of an object is a simple reference to another object which has its own prototype reference set to yet
another object
 All objects are descended from 'Object' and they inherit properties from Object.prototype, but they may be
overridden
 'null', by definition, has no prototype, and acts as the final link in this prototype chain
 New objects are created by copying the structure of an existing prototype object
Inheritance in JavaScript
JavaScript Overview - Inheritance
JavaScript Overview - Inheritance
JavaScript Overview - Functions
In JavaScript, functions are objects and are used to perform a task or calculates a value.
Functions have properties and methods that they inherit from the Function object. It is possible to add new
properties and methods to functions.
 Functions are values that can be bound to names, passed as arguments, returned from other functions
 Functions are applied to arguments
 The arguments are passed by sharing, which is also called “pass by value”
 Function bodies have zero or more expressions
 Function application evaluates whatever is returned with the return keyword, or to 'undefined'
 Function application creates a scope. Scopes are nested and free variable references are closed over
 Variables can shadow variables in an enclosing scope
JavaScript Overview - Functions
Function declarations (they are hoisted — moved in their entirety to the beginning of the current scope)
JavaScript Overview - Functions
Function object (all functions inherit from it) has the following properties:
 arguments: An Array/object containing the arguments passed to the function
 arguments.length: Stores the number of arguments in the array
 arguments.callee: Pointer to the executing function (allows anonymous functions to recurse)
 length: The number of arguments the function was expecting
 constructor: function pointer to the constructor function
 prototype: allows the creation of prototypes
 Function object has the following methods:
 apply: A method that lets you more easily pass function arguments
 call: Allows you to call a function within a different context
 bind: creates a new function that, when called, has its 'this' set to the provided value, with a given sequence of
arguments preceding any provided when the new function is called
 toString: Returns the source of the function as a string
JavaScript Overview - Functions
JavaScript Overview - Closures
Closures are functions that refer to independent (free) variables.
Function defined in the closure 'remembers' the environment in which it was created. A closure, unlike a plain function
pointer, allows a function to access those free variables even when invoked outside its immediate lexical scope.
 Simply accessing variables outside of your immediate lexical scope creates a closure
 Inner function get full access to all the values defined in the outer function, not the other way around
JavaScript Overview - Closures
Functional Programming Overview
 What is functional programming?
 Why Functional?
 A motivating example(?)
Functional Programming Overview – What is
functional programming?
 First Class Functions:
stored in variables, passed as arguments to functions, created within functions and returned from functions
 Higher Order Functions:
Function that can accept functions as arguments, and/or can return a function
 No Side Effects:
Function that does something other than returning the result is said to have side effects
 Referential Transparency:
For a given set of arguments, the same code should always output the same value, only by changing arguments can a
output value be different
 Immutability:
Inability for variables to change their values once created. In other words, all things created stay constant
 Currying / Partial Application:
Ability of a function to return a new function until it receives all it's arguments. Calling a curried function with only some
of its arguments is called partial application
 Tail Call Optimization:
Ability to avoid allocating a new stack frame for a function call. The most common use is tail-recursion, where a recursive
function uses constant stack space.
Functional Programming Overview – What Is
functional programming?
"Functional programming isn't the goal. The goal is to simplify the complicated."
 Write less code
 Fewer errors
 Easy concurrency
 Testability
Functional Programming Overview – Why functional
programming?
... but who has time to learn new stuff (all the time)?
Functional Programming Overview – Motivating example *
*Hat tip to Brian Lonsdorf, aka @drboolean. Watch his videos, great fun and motivating stuff!
Hey Underscore, You're Doing It Wrong!
Functional programming patterns for the non-mathematician!
Functional Programming Overview – Motivating example
Functional Programming Overview – Motivating example
Functional Programming Techniques
 Functional JavaScript
 Pure Function, Higher Order Functions
 Composition, Combinators
 Currying/Partial Application
 Filter, Map, Reduce
 Try it out yourself...
Functional Programming Techniques – Functional
JavaScript
JavaScript allows a variety of different programming paradigms: OO, functional, procedural
Although not a pure functional programming language, it allows one to program in a functional way.
Supports:
 First Class Functions
 Higher Order Functions
 Anonymous functions
 Closures
Functional Programming Techniques – Functional
JavaScript
JavaScript allows a variety of different programming paradigms: OO, functional, procedural
Although not a pure functional programming language, it allows one to program in a functional way.
Does not support directly, but possible with some discipline :)
 Pure functions
 Immutability
 No Side Effects
Functional Programming Techniques – Functional
JavaScript
JavaScript allows a variety of different programming paradigms: OO, functional, procedural
Although not a pure functional programming language, it allows one to program in a functional way.
Does not support directly, but possible with use of libraries or with ES6:
 Currying/Partial Application
 Tail call optimization
 Pattern matching
 Lazy Evaluation
Functional Programming Techniques – Pure Function
A function is considered pure if the result depends only on the arguments, and it has no side effects
The only result of invoking a pure function is the return value.
 Same input, same ouput
 No side effects
 Can be cached
 Easy to test
 Allows code to run in parallel
Functional Programming Techniques – Pure Function
Functional Programming Techniques – Higher Order
Function
Functional Programming Techniques - Composition
Functional Programming Techniques - Combinators
Ability to use functions as building blocks to make new functions
Function composition is simply one of many combinators.
Tacit programming (point-free programming) is a programming paradigm in which a function definition does not include
information regarding its arguments, using combinators and composition in the function declaration instead of arguments
Some Examples*:
 splat
 get
 pluck
*Taken from Reginald Braithwaite's, aka @raganwald, article: Combinator Recipes for Working With Objects in JavaScript
Be sure to check out his projects and books!
Functional Programming Techniques - Combinators
Functional Programming Techniques - Combinators
Functional Programming Techniques - Combinators
Functional Programming Techniques - Currying / Partial application
Currying produces a function that will return a new function until it receives all it's arguments
Currying enables Partial Application, and together they help:
 Making generic functions
 Building new functions by applying arguments
 Better granularity of functions
 More powerful function composition
Functional Programming Techniques – Example: Filter
The filter method transforms an array by applying a predicate function to all of its elements, and building a new array
from the elements for which predicate returned true.
Functional Programming Techniques – Example: Map
Map takes a function as an argument, and applies it to each of the elements of the array, then returns the results in a new
array
Functional Programming Techniques – Example: Reduce (Fold)
Reduce applies a function against an accumulator and each value of the array (from left-to-right) to reduce it to a single
value
Functional Programming Techniques – Try it yourself
@timoxley: functional-javascript-workshop
Resources
This presentation: Functional Javascript/
Original Deck/CodeMirror plugin by Irene Ros: deck.js-codemirror
Javascript Functional (and not so functional*) programming libraries:
 allong.es: http://allong.es/
 Ramda: https://github.com/CrossEye/ramda
 LambdaJs: https://github.com/loop-recur/lambdajs/
 Falktale: http://folktale.github.io/
 *Underscore: http://underscorejs.org/
 *Lo-Dash: http://lodash.com/
Books on Functional JavaScript
 Functional JavaScript, Michael Fogus
 Eloquent JavaScript, Marijn Haverbeke
 JavaScript Allongé, Reginald Braithwaite

More Related Content

What's hot (20)

Dev Concepts: Functional Programming
Dev Concepts: Functional ProgrammingDev Concepts: Functional Programming
Dev Concepts: Functional Programming
Svetlin Nakov
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programming
Dhaval Dalal
 
Books
BooksBooks
Books
Steven Foster Murray
 
Functors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaFunctors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In Scala
Knoldus Inc.
 
379008-rc217-functionalprogramming
379008-rc217-functionalprogramming379008-rc217-functionalprogramming
379008-rc217-functionalprogramming
Luis Atencio
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programming
Konrad Szydlo
 
Ruby Functional Programming
Ruby Functional ProgrammingRuby Functional Programming
Ruby Functional Programming
Geison Goes
 
Java 8 by example!
Java 8 by example!Java 8 by example!
Java 8 by example!
Mark Harrison
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
Dhruvin Shah
 
Create and analyse programs
Create and analyse programsCreate and analyse programs
Create and analyse programs
Dr. C.V. Suresh Babu
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Maaz Hasan
 
An Introduction to Functional Programming with Javascript
An Introduction to Functional Programming with JavascriptAn Introduction to Functional Programming with Javascript
An Introduction to Functional Programming with Javascript
Doug Sparling
 
Eclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 OverviewEclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 Overview
Eclipse Day India
 
Functional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smartFunctional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smart
Chen Fisher
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
Nikhil Pandit
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
Learn By Watch
 
Function Parameters
Function ParametersFunction Parameters
Function Parameters
primeteacher32
 
Python Built-in Functions and Use cases
Python Built-in Functions and Use casesPython Built-in Functions and Use cases
Python Built-in Functions and Use cases
Srajan Mor
 
Functional programming and ruby in functional style
Functional programming and ruby in functional styleFunctional programming and ruby in functional style
Functional programming and ruby in functional style
Niranjan Sarade
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar
 
Dev Concepts: Functional Programming
Dev Concepts: Functional ProgrammingDev Concepts: Functional Programming
Dev Concepts: Functional Programming
Svetlin Nakov
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programming
Dhaval Dalal
 
Functors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaFunctors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In Scala
Knoldus Inc.
 
379008-rc217-functionalprogramming
379008-rc217-functionalprogramming379008-rc217-functionalprogramming
379008-rc217-functionalprogramming
Luis Atencio
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programming
Konrad Szydlo
 
Ruby Functional Programming
Ruby Functional ProgrammingRuby Functional Programming
Ruby Functional Programming
Geison Goes
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
Dhruvin Shah
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Maaz Hasan
 
An Introduction to Functional Programming with Javascript
An Introduction to Functional Programming with JavascriptAn Introduction to Functional Programming with Javascript
An Introduction to Functional Programming with Javascript
Doug Sparling
 
Eclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 OverviewEclipse Day India 2015 - Java 8 Overview
Eclipse Day India 2015 - Java 8 Overview
Eclipse Day India
 
Functional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smartFunctional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smart
Chen Fisher
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
Nikhil Pandit
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
Learn By Watch
 
Python Built-in Functions and Use cases
Python Built-in Functions and Use casesPython Built-in Functions and Use cases
Python Built-in Functions and Use cases
Srajan Mor
 
Functional programming and ruby in functional style
Functional programming and ruby in functional styleFunctional programming and ruby in functional style
Functional programming and ruby in functional style
Niranjan Sarade
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar
 

Similar to Functional JavaScript Fundamentals (20)

Functional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks weekFunctional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks week
yoavrubin
 
Основы функционального JS
Основы функционального JSОсновы функционального JS
Основы функционального JS
Анна Луць
 
Functional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis AtencioFunctional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis Atencio
Luis Atencio
 
Functional programming
Functional programmingFunctional programming
Functional programming
S M Asaduzzaman
 
Functional Programming with Javascript
Functional Programming with JavascriptFunctional Programming with Javascript
Functional Programming with Javascript
Deepankar Chopra
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course
yoavrubin
 
Functional Programming in JavaScript
Functional Programming in JavaScriptFunctional Programming in JavaScript
Functional Programming in JavaScript
Will Livengood
 
Functional programming 101
Functional programming 101Functional programming 101
Functional programming 101
Maneesh Chaturvedi
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
Hoàng Lâm Huỳnh
 
Introduction to Functional Programming (w/ JS)
Introduction to Functional Programming (w/ JS)Introduction to Functional Programming (w/ JS)
Introduction to Functional Programming (w/ JS)
Allan Marques Baptista
 
25-functions.ppt
25-functions.ppt25-functions.ppt
25-functions.ppt
JyothiAmpally
 
Why Functional Programming So Hard?
Why Functional Programming So Hard?Why Functional Programming So Hard?
Why Functional Programming So Hard?
Ilya Sidorov
 
Js in-ten-minutes
Js in-ten-minutesJs in-ten-minutes
Js in-ten-minutes
Phong Vân
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
Quinton Sheppard
 
Things about Functional JavaScript
Things about Functional JavaScriptThings about Functional JavaScript
Things about Functional JavaScript
ChengHui Weng
 
A Skeptics guide to functional style javascript
A Skeptics guide to functional style javascriptA Skeptics guide to functional style javascript
A Skeptics guide to functional style javascript
jonathanfmills
 
Functional programming in JavaScript
Functional programming in JavaScriptFunctional programming in JavaScript
Functional programming in JavaScript
Joseph Smith
 
introtofunctionalprogramming2-170301075633.pdf
introtofunctionalprogramming2-170301075633.pdfintrotofunctionalprogramming2-170301075633.pdf
introtofunctionalprogramming2-170301075633.pdf
RodulfoGabrito
 
Functional programing jargon
Functional programing jargonFunctional programing jargon
Functional programing jargon
Remo Jansen
 
Functional programing in Javascript (lite intro)
Functional programing in Javascript (lite intro)Functional programing in Javascript (lite intro)
Functional programing in Javascript (lite intro)
Nikos Kalogridis
 
Functional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks weekFunctional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks week
yoavrubin
 
Основы функционального JS
Основы функционального JSОсновы функционального JS
Основы функционального JS
Анна Луць
 
Functional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis AtencioFunctional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis Atencio
Luis Atencio
 
Functional Programming with Javascript
Functional Programming with JavascriptFunctional Programming with Javascript
Functional Programming with Javascript
Deepankar Chopra
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course
yoavrubin
 
Functional Programming in JavaScript
Functional Programming in JavaScriptFunctional Programming in JavaScript
Functional Programming in JavaScript
Will Livengood
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
Hoàng Lâm Huỳnh
 
Introduction to Functional Programming (w/ JS)
Introduction to Functional Programming (w/ JS)Introduction to Functional Programming (w/ JS)
Introduction to Functional Programming (w/ JS)
Allan Marques Baptista
 
Why Functional Programming So Hard?
Why Functional Programming So Hard?Why Functional Programming So Hard?
Why Functional Programming So Hard?
Ilya Sidorov
 
Js in-ten-minutes
Js in-ten-minutesJs in-ten-minutes
Js in-ten-minutes
Phong Vân
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
Quinton Sheppard
 
Things about Functional JavaScript
Things about Functional JavaScriptThings about Functional JavaScript
Things about Functional JavaScript
ChengHui Weng
 
A Skeptics guide to functional style javascript
A Skeptics guide to functional style javascriptA Skeptics guide to functional style javascript
A Skeptics guide to functional style javascript
jonathanfmills
 
Functional programming in JavaScript
Functional programming in JavaScriptFunctional programming in JavaScript
Functional programming in JavaScript
Joseph Smith
 
introtofunctionalprogramming2-170301075633.pdf
introtofunctionalprogramming2-170301075633.pdfintrotofunctionalprogramming2-170301075633.pdf
introtofunctionalprogramming2-170301075633.pdf
RodulfoGabrito
 
Functional programing jargon
Functional programing jargonFunctional programing jargon
Functional programing jargon
Remo Jansen
 
Functional programing in Javascript (lite intro)
Functional programing in Javascript (lite intro)Functional programing in Javascript (lite intro)
Functional programing in Javascript (lite intro)
Nikos Kalogridis
 
Ad

Recently uploaded (20)

How AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptxHow AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
kalichargn70th171
 
Issues in AI Presentation and machine learning.pptx
Issues in AI Presentation and machine learning.pptxIssues in AI Presentation and machine learning.pptx
Issues in AI Presentation and machine learning.pptx
Jalalkhan657136
 
UberEats clone app Development TechBuilder
UberEats clone app Development  TechBuilderUberEats clone app Development  TechBuilder
UberEats clone app Development TechBuilder
TechBuilder
 
List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...
List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...
List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...
Philip Schwarz
 
Optimising Claims Management with Claims Processing Systems
Optimising Claims Management with Claims Processing SystemsOptimising Claims Management with Claims Processing Systems
Optimising Claims Management with Claims Processing Systems
Insurance Tech Services
 
SQL-COMMANDS instructionsssssssssss.pptx
SQL-COMMANDS instructionsssssssssss.pptxSQL-COMMANDS instructionsssssssssss.pptx
SQL-COMMANDS instructionsssssssssss.pptx
Ashlei5
 
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
officeiqai
 
grade 9 ai project cycle Artificial intelligence.pptx
grade 9 ai project cycle Artificial intelligence.pptxgrade 9 ai project cycle Artificial intelligence.pptx
grade 9 ai project cycle Artificial intelligence.pptx
manikumar465287
 
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATIONAI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
miso_uam
 
ICDL FULL STANDARD 2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdf
ICDL FULL STANDARD  2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdfICDL FULL STANDARD  2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdf
ICDL FULL STANDARD 2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdf
M. Luisetto Pharm.D.Spec. Pharmacology
 
AI Alternative - Discover the best AI tools and their alternatives
AI Alternative - Discover the best AI tools and their alternativesAI Alternative - Discover the best AI tools and their alternatives
AI Alternative - Discover the best AI tools and their alternatives
AI Alternative
 
Facility Management Solution - TeroTAM CMMS Software
Facility Management Solution - TeroTAM CMMS SoftwareFacility Management Solution - TeroTAM CMMS Software
Facility Management Solution - TeroTAM CMMS Software
TeroTAM
 
zOS CommServer support for the Network Express feature on z17
zOS CommServer support for the Network Express feature on z17zOS CommServer support for the Network Express feature on z17
zOS CommServer support for the Network Express feature on z17
zOSCommserver
 
How a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdf
How a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdfHow a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdf
How a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdf
mary rojas
 
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
gauravvmanchandaa200
 
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdfBoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
Ortus Solutions, Corp
 
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdfHow to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
QuickBooks Training
 
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdfHow to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
victordsane
 
Scalefusion Remote Access for Apple Devices
Scalefusion Remote Access for Apple DevicesScalefusion Remote Access for Apple Devices
Scalefusion Remote Access for Apple Devices
Scalefusion
 
Design by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First DevelopmentDesign by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First Development
Par-Tec S.p.A.
 
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptxHow AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
kalichargn70th171
 
Issues in AI Presentation and machine learning.pptx
Issues in AI Presentation and machine learning.pptxIssues in AI Presentation and machine learning.pptx
Issues in AI Presentation and machine learning.pptx
Jalalkhan657136
 
UberEats clone app Development TechBuilder
UberEats clone app Development  TechBuilderUberEats clone app Development  TechBuilder
UberEats clone app Development TechBuilder
TechBuilder
 
List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...
List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...
List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfol...
Philip Schwarz
 
Optimising Claims Management with Claims Processing Systems
Optimising Claims Management with Claims Processing SystemsOptimising Claims Management with Claims Processing Systems
Optimising Claims Management with Claims Processing Systems
Insurance Tech Services
 
SQL-COMMANDS instructionsssssssssss.pptx
SQL-COMMANDS instructionsssssssssss.pptxSQL-COMMANDS instructionsssssssssss.pptx
SQL-COMMANDS instructionsssssssssss.pptx
Ashlei5
 
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
officeiqai
 
grade 9 ai project cycle Artificial intelligence.pptx
grade 9 ai project cycle Artificial intelligence.pptxgrade 9 ai project cycle Artificial intelligence.pptx
grade 9 ai project cycle Artificial intelligence.pptx
manikumar465287
 
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATIONAI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
miso_uam
 
ICDL FULL STANDARD 2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdf
ICDL FULL STANDARD  2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdfICDL FULL STANDARD  2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdf
ICDL FULL STANDARD 2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdf
M. Luisetto Pharm.D.Spec. Pharmacology
 
AI Alternative - Discover the best AI tools and their alternatives
AI Alternative - Discover the best AI tools and their alternativesAI Alternative - Discover the best AI tools and their alternatives
AI Alternative - Discover the best AI tools and their alternatives
AI Alternative
 
Facility Management Solution - TeroTAM CMMS Software
Facility Management Solution - TeroTAM CMMS SoftwareFacility Management Solution - TeroTAM CMMS Software
Facility Management Solution - TeroTAM CMMS Software
TeroTAM
 
zOS CommServer support for the Network Express feature on z17
zOS CommServer support for the Network Express feature on z17zOS CommServer support for the Network Express feature on z17
zOS CommServer support for the Network Express feature on z17
zOSCommserver
 
How a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdf
How a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdfHow a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdf
How a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdf
mary rojas
 
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
Risk Management in Software Projects: Identifying, Analyzing, and Controlling...
gauravvmanchandaa200
 
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdfBoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
Ortus Solutions, Corp
 
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdfHow to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
QuickBooks Training
 
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdfHow to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
victordsane
 
Scalefusion Remote Access for Apple Devices
Scalefusion Remote Access for Apple DevicesScalefusion Remote Access for Apple Devices
Scalefusion Remote Access for Apple Devices
Scalefusion
 
Design by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First DevelopmentDesign by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First Development
Par-Tec S.p.A.
 
Ad

Functional JavaScript Fundamentals

  • 1. Functional JavaScript Follow me twitter: @djidja8 This deck online with live code editing: functional-js
  • 2. JavaScript Overview  Type System  Primitive Values  Objects  Inheritance  Functions  Closures
  • 3. JavaScript Overview – Type System JavaScript has dynamic and loosely typed type system with two main types: Primitive (value) types:  number  string  boolean  null  Undefined Object (reference) types:  Object  Function  Array  Date  RegExp  *Wrappers for primitives: Boolean, Number, String
  • 4. JavaScript Overview – Type System @vijayan blog: JavaScript Type Model
  • 6. JavaScript Overview – Primitive Values
  • 9. JavaScript Overview - Inheritance JavaScript supports a prototype-based inheritance. Inheritance is performed by creating new objects directly, based on existing ones, existing object is assigned as the prototype of the new object and then inherited behavior can be changed or new behavior can be added to the new object.  The prototype of an object is a simple reference to another object which has its own prototype reference set to yet another object  All objects are descended from 'Object' and they inherit properties from Object.prototype, but they may be overridden  'null', by definition, has no prototype, and acts as the final link in this prototype chain  New objects are created by copying the structure of an existing prototype object Inheritance in JavaScript
  • 10. JavaScript Overview - Inheritance
  • 11. JavaScript Overview - Inheritance
  • 12. JavaScript Overview - Functions In JavaScript, functions are objects and are used to perform a task or calculates a value. Functions have properties and methods that they inherit from the Function object. It is possible to add new properties and methods to functions.  Functions are values that can be bound to names, passed as arguments, returned from other functions  Functions are applied to arguments  The arguments are passed by sharing, which is also called “pass by value”  Function bodies have zero or more expressions  Function application evaluates whatever is returned with the return keyword, or to 'undefined'  Function application creates a scope. Scopes are nested and free variable references are closed over  Variables can shadow variables in an enclosing scope
  • 13. JavaScript Overview - Functions Function declarations (they are hoisted — moved in their entirety to the beginning of the current scope)
  • 14. JavaScript Overview - Functions Function object (all functions inherit from it) has the following properties:  arguments: An Array/object containing the arguments passed to the function  arguments.length: Stores the number of arguments in the array  arguments.callee: Pointer to the executing function (allows anonymous functions to recurse)  length: The number of arguments the function was expecting  constructor: function pointer to the constructor function  prototype: allows the creation of prototypes  Function object has the following methods:  apply: A method that lets you more easily pass function arguments  call: Allows you to call a function within a different context  bind: creates a new function that, when called, has its 'this' set to the provided value, with a given sequence of arguments preceding any provided when the new function is called  toString: Returns the source of the function as a string
  • 16. JavaScript Overview - Closures Closures are functions that refer to independent (free) variables. Function defined in the closure 'remembers' the environment in which it was created. A closure, unlike a plain function pointer, allows a function to access those free variables even when invoked outside its immediate lexical scope.  Simply accessing variables outside of your immediate lexical scope creates a closure  Inner function get full access to all the values defined in the outer function, not the other way around
  • 18. Functional Programming Overview  What is functional programming?  Why Functional?  A motivating example(?)
  • 19. Functional Programming Overview – What is functional programming?  First Class Functions: stored in variables, passed as arguments to functions, created within functions and returned from functions  Higher Order Functions: Function that can accept functions as arguments, and/or can return a function  No Side Effects: Function that does something other than returning the result is said to have side effects  Referential Transparency: For a given set of arguments, the same code should always output the same value, only by changing arguments can a output value be different  Immutability: Inability for variables to change their values once created. In other words, all things created stay constant  Currying / Partial Application: Ability of a function to return a new function until it receives all it's arguments. Calling a curried function with only some of its arguments is called partial application  Tail Call Optimization: Ability to avoid allocating a new stack frame for a function call. The most common use is tail-recursion, where a recursive function uses constant stack space.
  • 20. Functional Programming Overview – What Is functional programming? "Functional programming isn't the goal. The goal is to simplify the complicated."  Write less code  Fewer errors  Easy concurrency  Testability
  • 21. Functional Programming Overview – Why functional programming? ... but who has time to learn new stuff (all the time)?
  • 22. Functional Programming Overview – Motivating example * *Hat tip to Brian Lonsdorf, aka @drboolean. Watch his videos, great fun and motivating stuff! Hey Underscore, You're Doing It Wrong! Functional programming patterns for the non-mathematician!
  • 23. Functional Programming Overview – Motivating example
  • 24. Functional Programming Overview – Motivating example
  • 25. Functional Programming Techniques  Functional JavaScript  Pure Function, Higher Order Functions  Composition, Combinators  Currying/Partial Application  Filter, Map, Reduce  Try it out yourself...
  • 26. Functional Programming Techniques – Functional JavaScript JavaScript allows a variety of different programming paradigms: OO, functional, procedural Although not a pure functional programming language, it allows one to program in a functional way. Supports:  First Class Functions  Higher Order Functions  Anonymous functions  Closures
  • 27. Functional Programming Techniques – Functional JavaScript JavaScript allows a variety of different programming paradigms: OO, functional, procedural Although not a pure functional programming language, it allows one to program in a functional way. Does not support directly, but possible with some discipline :)  Pure functions  Immutability  No Side Effects
  • 28. Functional Programming Techniques – Functional JavaScript JavaScript allows a variety of different programming paradigms: OO, functional, procedural Although not a pure functional programming language, it allows one to program in a functional way. Does not support directly, but possible with use of libraries or with ES6:  Currying/Partial Application  Tail call optimization  Pattern matching  Lazy Evaluation
  • 29. Functional Programming Techniques – Pure Function A function is considered pure if the result depends only on the arguments, and it has no side effects The only result of invoking a pure function is the return value.  Same input, same ouput  No side effects  Can be cached  Easy to test  Allows code to run in parallel
  • 31. Functional Programming Techniques – Higher Order Function
  • 33. Functional Programming Techniques - Combinators Ability to use functions as building blocks to make new functions Function composition is simply one of many combinators. Tacit programming (point-free programming) is a programming paradigm in which a function definition does not include information regarding its arguments, using combinators and composition in the function declaration instead of arguments Some Examples*:  splat  get  pluck *Taken from Reginald Braithwaite's, aka @raganwald, article: Combinator Recipes for Working With Objects in JavaScript Be sure to check out his projects and books!
  • 37. Functional Programming Techniques - Currying / Partial application Currying produces a function that will return a new function until it receives all it's arguments Currying enables Partial Application, and together they help:  Making generic functions  Building new functions by applying arguments  Better granularity of functions  More powerful function composition
  • 38. Functional Programming Techniques – Example: Filter The filter method transforms an array by applying a predicate function to all of its elements, and building a new array from the elements for which predicate returned true.
  • 39. Functional Programming Techniques – Example: Map Map takes a function as an argument, and applies it to each of the elements of the array, then returns the results in a new array
  • 40. Functional Programming Techniques – Example: Reduce (Fold) Reduce applies a function against an accumulator and each value of the array (from left-to-right) to reduce it to a single value
  • 41. Functional Programming Techniques – Try it yourself @timoxley: functional-javascript-workshop
  • 42. Resources This presentation: Functional Javascript/ Original Deck/CodeMirror plugin by Irene Ros: deck.js-codemirror Javascript Functional (and not so functional*) programming libraries:  allong.es: http://allong.es/  Ramda: https://github.com/CrossEye/ramda  LambdaJs: https://github.com/loop-recur/lambdajs/  Falktale: http://folktale.github.io/  *Underscore: http://underscorejs.org/  *Lo-Dash: http://lodash.com/ Books on Functional JavaScript  Functional JavaScript, Michael Fogus  Eloquent JavaScript, Marijn Haverbeke  JavaScript Allongé, Reginald Braithwaite