SlideShare a Scribd company logo
Functional Programming In JavaScriptFunctional Programming In JavaScript
Nikhil Kumar | Software Consultant
KnÓldus Software LLP
Nikhil Kumar | Software Consultant
KnÓldus Software LLP
Functional programming in Javascript
AgendaAgenda
● Functional Programming : The Benefits
● Basic version Vs Filter
● Find
● Map
● Reduce
● Closures
● Now: var, let & const
● IIFE
All with comparisons
Functional programming is a paradigm which concentrates on
computing results rather than on performing actions. That is, when
you call a function, the only significant effect that the function has is
usually to compute a value and return it. Of course, behind the
scenes the function is using CPU time, allocating and writing memory,
but from the programmer's point of view, the primary effect is the
return value
Functional programming is a paradigm which concentrates on
computing results rather than on performing actions. That is, when
you call a function, the only significant effect that the function has is
usually to compute a value and return it. Of course, behind the
scenes the function is using CPU time, allocating and writing memory,
but from the programmer's point of view, the primary effect is the
return value
F P
Benefits of FP
 Less Bugs (less code)
 Easier to reason about
 Less Time
 Re-use more code.
FilterFilter
Filter is method on array objects that takes a function as a argument.
Filter expect its callback to return true or false.
var porche = cars.filter(function(carName){
return carName.brand === 'porche'
})
FindFind
works like as filter, but just return the first value.
var porche = cars.find(function(carName){
return carName.brand === 'porche'
})
MapMap
Map is function on the array object.
Map expect the callback function to return a transformed object,
Above 3 are used in – list transformation, they turn your list into something else.
var carList = []
for(var i = 0; i < cars.length; i++){
carList.push(cars[i].name)
}
ReduceReduce
Reduce is awesome, using reduce you can create functions like, map, find, filter or any other
list transformation. Reduce is super List Transformation tool, you can it to meet or your
requirements.
var priceSum = cars.reduce(function(sum, cars){
console.log("The sum of all cars", + sum, cars);
return sum + cars.price
},0);
ClosuresClosures
var myName = "nikhil"
function namesFun(){
console.log("Hey the name is " + myName);
}
namesFun();
Basically functions in javascript are closures actually, they can access the variables outside of
the functions, in languages that does not support closures we cannot do so.
Closure is a function inside a function.
Var is function scope let is block scope and don't talk about const
here.
Var is function scope let is block scope and don't talk about const
here.
Var => let => const
function count(){
for(var i = 0; i < 10; i++){
console.log(i);
}
}
count();
console.log(i);
//let
"use strict";
var i = 500;
for( i = 0; i< 101; i++){
console.log(i)
}
if(true){
/*let*/ i = 34000;
}
console.log(" show me ", i);
Using Let
let allows you to declare variables that are limited in scope to the block, statement, or
expression on which it is used. This is unlike the var keyword, which defines a variable
globally, or locally to an entire function regardless of block scope.
function varTest() {
var x = 1;
if (true) {
var x = 2; // same variable!
console.log(x); // 2
}
console.log(x); // 2
}
function letTest() {
let x = 1;
if (true) {
let x = 2; // different variable
console.log(x); // 2
}
console.log(x); // 1
}
Using Const
Constants are block-scoped, much like variables defined using the let statement. The value of
a constant cannot change through re-assignment, and it can't be redeclared.
The const declaration creates a read-only reference to a value. It does not mean the value
it holds is immutable, just that the variable identifier cannot be reassigned. For instance, in
case the content is an object, this means the object itself can still be altered.
"use strict";
const x= {
y: 10
}
//this can be done
x.y = 11;
//BUT
x = {
z:5;
}
console.log(x);
IIFE: Immediately Invoked Function Expression:IIFE: Immediately Invoked Function Expression:
(function(){
for(var i = 0; i < 10; i++){
console.log(i);
}
})();
References
Mozilla Documentation
Presenter
nikhil@knoldus.com
Presenter
nikhil@knoldus.com
Organizer
@Knolspeak
http://www.knoldus.com
http://blog.knoldus.com
Organizer
@Knolspeak
http://www.knoldus.com
http://blog.knoldus.com
Thanks

More Related Content

What's hot (20)

operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
gourav kottawar
 
An Introduction to Reactive Cocoa
An Introduction to Reactive Cocoa
SmartLogic
 
Introduction to RxJava on Android
Introduction to RxJava on Android
Chris Arriola
 
Java script
Java script
Dhananjay Kumar
 
Operator Overloading
Operator Overloading
Nilesh Dalvi
 
Cocoa heads 09112017
Cocoa heads 09112017
Vincent Pradeilles
 
Operator overloading and type conversion in cpp
Operator overloading and type conversion in cpp
rajshreemuthiah
 
OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++
Aabha Tiwari
 
JavaScript for real men
JavaScript for real men
Ivano Malavolta
 
Operator overloading
Operator overloading
ArunaDevi63
 
Operator overloading
Operator overloading
Garima Singh Makhija
 
Lec 26.27-operator overloading
Lec 26.27-operator overloading
Princess Sam
 
Operator overloading
Operator overloading
Kumar
 
Overloading
Overloading
poonamchopra7975
 
Operator overloading
Operator overloading
abhay singh
 
From object oriented to functional domain modeling
From object oriented to functional domain modeling
Codemotion
 
ReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better Together
Colin Eberhardt
 
Function overloading and overriding
Function overloading and overriding
Rajab Ali
 
Javascript
Javascript
Tarek Raihan
 
operator overloading
operator overloading
Sorath Peetamber
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
gourav kottawar
 
An Introduction to Reactive Cocoa
An Introduction to Reactive Cocoa
SmartLogic
 
Introduction to RxJava on Android
Introduction to RxJava on Android
Chris Arriola
 
Operator Overloading
Operator Overloading
Nilesh Dalvi
 
Operator overloading and type conversion in cpp
Operator overloading and type conversion in cpp
rajshreemuthiah
 
OPERATOR OVERLOADING IN C++
OPERATOR OVERLOADING IN C++
Aabha Tiwari
 
Operator overloading
Operator overloading
ArunaDevi63
 
Lec 26.27-operator overloading
Lec 26.27-operator overloading
Princess Sam
 
Operator overloading
Operator overloading
Kumar
 
Operator overloading
Operator overloading
abhay singh
 
From object oriented to functional domain modeling
From object oriented to functional domain modeling
Codemotion
 
ReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better Together
Colin Eberhardt
 
Function overloading and overriding
Function overloading and overriding
Rajab Ali
 

Viewers also liked (20)

Deep dive into sass
Deep dive into sass
Knoldus Inc.
 
HTML5, CSS, JavaScript Style guide and coding conventions
HTML5, CSS, JavaScript Style guide and coding conventions
Knoldus Inc.
 
Introduction to BDD
Introduction to BDD
Knoldus Inc.
 
Akka Finite State Machine
Akka Finite State Machine
Knoldus Inc.
 
Mandrill Templates
Mandrill Templates
Knoldus Inc.
 
Fast dataarchitecture
Fast dataarchitecture
Knoldus Inc.
 
String interpolation
String interpolation
Knoldus Inc.
 
Introduction to ScalaZ
Introduction to ScalaZ
Knoldus Inc.
 
Introduction to Knockout Js
Introduction to Knockout Js
Knoldus Inc.
 
Lambda Architecture with Spark
Lambda Architecture with Spark
Knoldus Inc.
 
Cassandra - Tips And Techniques
Cassandra - Tips And Techniques
Knoldus Inc.
 
Introduction to Apache Cassandra
Introduction to Apache Cassandra
Knoldus Inc.
 
Getting started with typescript and angular 2
Getting started with typescript and angular 2
Knoldus Inc.
 
Introduction to AWS IAM
Introduction to AWS IAM
Knoldus Inc.
 
Petex 2016 Future Working Zone
Petex 2016 Future Working Zone
Andrew Zolnai
 
How the web was won
How the web was won
Andrew Zolnai
 
Introduction to Scala JS
Introduction to Scala JS
Knoldus Inc.
 
Getting Started With AureliaJs
Getting Started With AureliaJs
Knoldus Inc.
 
Akka streams
Akka streams
Knoldus Inc.
 
Drilling the Async Library
Drilling the Async Library
Knoldus Inc.
 
Deep dive into sass
Deep dive into sass
Knoldus Inc.
 
HTML5, CSS, JavaScript Style guide and coding conventions
HTML5, CSS, JavaScript Style guide and coding conventions
Knoldus Inc.
 
Introduction to BDD
Introduction to BDD
Knoldus Inc.
 
Akka Finite State Machine
Akka Finite State Machine
Knoldus Inc.
 
Mandrill Templates
Mandrill Templates
Knoldus Inc.
 
Fast dataarchitecture
Fast dataarchitecture
Knoldus Inc.
 
String interpolation
String interpolation
Knoldus Inc.
 
Introduction to ScalaZ
Introduction to ScalaZ
Knoldus Inc.
 
Introduction to Knockout Js
Introduction to Knockout Js
Knoldus Inc.
 
Lambda Architecture with Spark
Lambda Architecture with Spark
Knoldus Inc.
 
Cassandra - Tips And Techniques
Cassandra - Tips And Techniques
Knoldus Inc.
 
Introduction to Apache Cassandra
Introduction to Apache Cassandra
Knoldus Inc.
 
Getting started with typescript and angular 2
Getting started with typescript and angular 2
Knoldus Inc.
 
Introduction to AWS IAM
Introduction to AWS IAM
Knoldus Inc.
 
Petex 2016 Future Working Zone
Petex 2016 Future Working Zone
Andrew Zolnai
 
Introduction to Scala JS
Introduction to Scala JS
Knoldus Inc.
 
Getting Started With AureliaJs
Getting Started With AureliaJs
Knoldus Inc.
 
Drilling the Async Library
Drilling the Async Library
Knoldus Inc.
 
Ad

Similar to Functional programming in Javascript (20)

A Skeptics guide to functional style javascript
A Skeptics guide to functional style javascript
jonathanfmills
 
379008-rc217-functionalprogramming
379008-rc217-functionalprogramming
Luis Atencio
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
Quinton Sheppard
 
Functional JavaScript Fundamentals
Functional JavaScript Fundamentals
Srdjan Strbanovic
 
Js in-ten-minutes
Js in-ten-minutes
Phong Vân
 
25-functions.ppt
25-functions.ppt
JyothiAmpally
 
Functional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks week
yoavrubin
 
Deck 893ff61f-1fb8-4e15-a379-775dfdbcee77-7-14-55-78-171-219-304-310-388 (1)
Deck 893ff61f-1fb8-4e15-a379-775dfdbcee77-7-14-55-78-171-219-304-310-388 (1)
Justin Ezor
 
The JavaScript Programming Language
The JavaScript Programming Language
Mohammed Irfan Shaikh
 
Front end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript core
Web Zhao
 
Fewd week5 slides
Fewd week5 slides
William Myers
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
JWORKS powered by Ordina
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3
BeeNear
 
ES6: The future is now
ES6: The future is now
Sebastiano Armeli
 
Intro to Javascript
Intro to Javascript
Anjan Banda
 
Intro to React
Intro to React
Troy Miles
 
Lect-5--JavaScript-Intro-12032024-105816am.pptx
Lect-5--JavaScript-Intro-12032024-105816am.pptx
zainm7032
 
JavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptx
Megha V
 
Wintellect - Devscovery - Enterprise JavaScript Development 1 of 2
Wintellect - Devscovery - Enterprise JavaScript Development 1 of 2
Jeremy Likness
 
A Skeptics guide to functional style javascript
A Skeptics guide to functional style javascript
jonathanfmills
 
379008-rc217-functionalprogramming
379008-rc217-functionalprogramming
Luis Atencio
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
Quinton Sheppard
 
Functional JavaScript Fundamentals
Functional JavaScript Fundamentals
Srdjan Strbanovic
 
Js in-ten-minutes
Js in-ten-minutes
Phong Vân
 
Functional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks week
yoavrubin
 
Deck 893ff61f-1fb8-4e15-a379-775dfdbcee77-7-14-55-78-171-219-304-310-388 (1)
Deck 893ff61f-1fb8-4e15-a379-775dfdbcee77-7-14-55-78-171-219-304-310-388 (1)
Justin Ezor
 
Front end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript core
Web Zhao
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
JWORKS powered by Ordina
 
Fii Practic Frontend - BeeNear - laborator3
Fii Practic Frontend - BeeNear - laborator3
BeeNear
 
Intro to Javascript
Intro to Javascript
Anjan Banda
 
Intro to React
Intro to React
Troy Miles
 
Lect-5--JavaScript-Intro-12032024-105816am.pptx
Lect-5--JavaScript-Intro-12032024-105816am.pptx
zainm7032
 
JavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptx
Megha V
 
Wintellect - Devscovery - Enterprise JavaScript Development 1 of 2
Wintellect - Devscovery - Enterprise JavaScript Development 1 of 2
Jeremy Likness
 
Ad

More from Knoldus Inc. (20)

Angular Hydration Presentation (FrontEnd)
Angular Hydration Presentation (FrontEnd)
Knoldus Inc.
 
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Knoldus Inc.
 
Self-Healing Test Automation Framework - Healenium
Self-Healing Test Automation Framework - Healenium
Knoldus Inc.
 
Kanban Metrics Presentation (Project Management)
Kanban Metrics Presentation (Project Management)
Knoldus Inc.
 
Java 17 features and implementation.pptx
Java 17 features and implementation.pptx
Knoldus Inc.
 
Chaos Mesh Introducing Chaos in Kubernetes
Chaos Mesh Introducing Chaos in Kubernetes
Knoldus Inc.
 
GraalVM - A Step Ahead of JVM Presentation
GraalVM - A Step Ahead of JVM Presentation
Knoldus Inc.
 
Nomad by HashiCorp Presentation (DevOps)
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
Nomad by HashiCorp Presentation (DevOps)
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
DAPR - Distributed Application Runtime Presentation
DAPR - Distributed Application Runtime Presentation
Knoldus Inc.
 
Introduction to Azure Virtual WAN Presentation
Introduction to Azure Virtual WAN Presentation
Knoldus Inc.
 
Introduction to Argo Rollouts Presentation
Introduction to Argo Rollouts Presentation
Knoldus Inc.
 
Intro to Azure Container App Presentation
Intro to Azure Container App Presentation
Knoldus Inc.
 
Insights Unveiled Test Reporting and Observability Excellence
Insights Unveiled Test Reporting and Observability Excellence
Knoldus Inc.
 
Introduction to Splunk Presentation (DevOps)
Introduction to Splunk Presentation (DevOps)
Knoldus Inc.
 
Code Camp - Data Profiling and Quality Analysis Framework
Code Camp - Data Profiling and Quality Analysis Framework
Knoldus Inc.
 
AWS: Messaging Services in AWS Presentation
AWS: Messaging Services in AWS Presentation
Knoldus Inc.
 
Amazon Cognito: A Primer on Authentication and Authorization
Amazon Cognito: A Primer on Authentication and Authorization
Knoldus Inc.
 
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Knoldus Inc.
 
Managing State & HTTP Requests In Ionic.
Managing State & HTTP Requests In Ionic.
Knoldus Inc.
 
Angular Hydration Presentation (FrontEnd)
Angular Hydration Presentation (FrontEnd)
Knoldus Inc.
 
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Knoldus Inc.
 
Self-Healing Test Automation Framework - Healenium
Self-Healing Test Automation Framework - Healenium
Knoldus Inc.
 
Kanban Metrics Presentation (Project Management)
Kanban Metrics Presentation (Project Management)
Knoldus Inc.
 
Java 17 features and implementation.pptx
Java 17 features and implementation.pptx
Knoldus Inc.
 
Chaos Mesh Introducing Chaos in Kubernetes
Chaos Mesh Introducing Chaos in Kubernetes
Knoldus Inc.
 
GraalVM - A Step Ahead of JVM Presentation
GraalVM - A Step Ahead of JVM Presentation
Knoldus Inc.
 
Nomad by HashiCorp Presentation (DevOps)
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
Nomad by HashiCorp Presentation (DevOps)
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
DAPR - Distributed Application Runtime Presentation
DAPR - Distributed Application Runtime Presentation
Knoldus Inc.
 
Introduction to Azure Virtual WAN Presentation
Introduction to Azure Virtual WAN Presentation
Knoldus Inc.
 
Introduction to Argo Rollouts Presentation
Introduction to Argo Rollouts Presentation
Knoldus Inc.
 
Intro to Azure Container App Presentation
Intro to Azure Container App Presentation
Knoldus Inc.
 
Insights Unveiled Test Reporting and Observability Excellence
Insights Unveiled Test Reporting and Observability Excellence
Knoldus Inc.
 
Introduction to Splunk Presentation (DevOps)
Introduction to Splunk Presentation (DevOps)
Knoldus Inc.
 
Code Camp - Data Profiling and Quality Analysis Framework
Code Camp - Data Profiling and Quality Analysis Framework
Knoldus Inc.
 
AWS: Messaging Services in AWS Presentation
AWS: Messaging Services in AWS Presentation
Knoldus Inc.
 
Amazon Cognito: A Primer on Authentication and Authorization
Amazon Cognito: A Primer on Authentication and Authorization
Knoldus Inc.
 
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Knoldus Inc.
 
Managing State & HTTP Requests In Ionic.
Managing State & HTTP Requests In Ionic.
Knoldus Inc.
 

Recently uploaded (20)

IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
Open Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
UPDASP a project coordination unit ......
UPDASP a project coordination unit ......
withrj1
 
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Intelli grow
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Software Testing & it’s types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 
Migrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right Way
Alexander (Alex) Komyagin
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
Open Source Software Development Methods
Open Source Software Development Methods
VICTOR MAESTRE RAMIREZ
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
UPDASP a project coordination unit ......
UPDASP a project coordination unit ......
withrj1
 
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Intelli grow
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Software Testing & it’s types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 

Functional programming in Javascript

  • 1. Functional Programming In JavaScriptFunctional Programming In JavaScript Nikhil Kumar | Software Consultant KnÓldus Software LLP Nikhil Kumar | Software Consultant KnÓldus Software LLP
  • 3. AgendaAgenda ● Functional Programming : The Benefits ● Basic version Vs Filter ● Find ● Map ● Reduce ● Closures ● Now: var, let & const ● IIFE All with comparisons
  • 4. Functional programming is a paradigm which concentrates on computing results rather than on performing actions. That is, when you call a function, the only significant effect that the function has is usually to compute a value and return it. Of course, behind the scenes the function is using CPU time, allocating and writing memory, but from the programmer's point of view, the primary effect is the return value Functional programming is a paradigm which concentrates on computing results rather than on performing actions. That is, when you call a function, the only significant effect that the function has is usually to compute a value and return it. Of course, behind the scenes the function is using CPU time, allocating and writing memory, but from the programmer's point of view, the primary effect is the return value F P Benefits of FP  Less Bugs (less code)  Easier to reason about  Less Time  Re-use more code.
  • 5. FilterFilter Filter is method on array objects that takes a function as a argument. Filter expect its callback to return true or false. var porche = cars.filter(function(carName){ return carName.brand === 'porche' })
  • 6. FindFind works like as filter, but just return the first value. var porche = cars.find(function(carName){ return carName.brand === 'porche' })
  • 7. MapMap Map is function on the array object. Map expect the callback function to return a transformed object, Above 3 are used in – list transformation, they turn your list into something else. var carList = [] for(var i = 0; i < cars.length; i++){ carList.push(cars[i].name) }
  • 8. ReduceReduce Reduce is awesome, using reduce you can create functions like, map, find, filter or any other list transformation. Reduce is super List Transformation tool, you can it to meet or your requirements. var priceSum = cars.reduce(function(sum, cars){ console.log("The sum of all cars", + sum, cars); return sum + cars.price },0);
  • 9. ClosuresClosures var myName = "nikhil" function namesFun(){ console.log("Hey the name is " + myName); } namesFun(); Basically functions in javascript are closures actually, they can access the variables outside of the functions, in languages that does not support closures we cannot do so. Closure is a function inside a function.
  • 10. Var is function scope let is block scope and don't talk about const here. Var is function scope let is block scope and don't talk about const here. Var => let => const function count(){ for(var i = 0; i < 10; i++){ console.log(i); } } count(); console.log(i); //let "use strict"; var i = 500; for( i = 0; i< 101; i++){ console.log(i) } if(true){ /*let*/ i = 34000; } console.log(" show me ", i);
  • 11. Using Let let allows you to declare variables that are limited in scope to the block, statement, or expression on which it is used. This is unlike the var keyword, which defines a variable globally, or locally to an entire function regardless of block scope. function varTest() { var x = 1; if (true) { var x = 2; // same variable! console.log(x); // 2 } console.log(x); // 2 } function letTest() { let x = 1; if (true) { let x = 2; // different variable console.log(x); // 2 } console.log(x); // 1 }
  • 12. Using Const Constants are block-scoped, much like variables defined using the let statement. The value of a constant cannot change through re-assignment, and it can't be redeclared. The const declaration creates a read-only reference to a value. It does not mean the value it holds is immutable, just that the variable identifier cannot be reassigned. For instance, in case the content is an object, this means the object itself can still be altered. "use strict"; const x= { y: 10 } //this can be done x.y = 11; //BUT x = { z:5; } console.log(x);
  • 13. IIFE: Immediately Invoked Function Expression:IIFE: Immediately Invoked Function Expression: (function(){ for(var i = 0; i < 10; i++){ console.log(i); } })();

Editor's Notes

  • #5: (You can think of the WebView as a chromeless browser window that’s typically configured to run fullscreen.) This enables them to access device capabilities such as the accelerometer, camera, contacts, and more. These are capabilities that are often restricted to access from inside mobile browsers.
  • #15: Piyush Mishra