Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript as a functional language

I am looking get to grips with functional programming concepts.

I've used Javascript for many years for client side scripting in web applications and apart from using prototypes it was all simple DOM manipulation, input validation etc.

Of late, I have often read that Javascript is one of the languages that supports functional programming.

With my familiarity and experience with Javascript, my preference is to use it to learn functional programming. I expect I would be able to concentrate more on the main functional concepts and not get bogged down or distracted by a completely new syntax.

So in summary, is Javascript a good choice to learn functional programming concepts? What capabilities in Javascript are relevant/support functional programming?

like image 585
Ash Avatar asked Sep 28 '08 02:09

Ash


People also ask

Why JavaScript is not a functional language?

You can write functional programs in many object-oriented languages, such as JavaScript and Python, but these programs aren't truly functional since their constructs don't fully mesh with the framework and rules of functional programming.

Is JavaScript functional or imperative?

You can write JavaScript in the Declarative paradigm or the Imperative paradigm. This is what people mean when they say it's a multi-paradigm language. It's just that functional code follows the Declarative paradigm.

Is JavaScript a functional or object-oriented language?

What is JavaScript? JavaScript (often shortened to JS) is a lightweight, interpreted, object-oriented language with first-class functions, and is best known as the scripting language for Web pages, but it's used in many non-browser environments as well.

Can we do functional programming in JavaScript?

JavaScript is a multi-paradigm language, which means that we can easily mix a lot of different paradigms inside a simple piece of JavaScript code. We can use object-oriented, procedural and functional programming paradigms all at the same time in JavaScript.


2 Answers

JavaScript supports first class functions. See Use functional programming techniques to write elegant JavaScript.

like image 75
Mark Cidade Avatar answered Sep 21 '22 09:09

Mark Cidade


Higher Order Javascript is a great way to get familiar with the functional aspects of javascript. It's also a relatively short read in case you want to get your feet wet without diving into a larger book.

like image 30
kamens Avatar answered Sep 19 '22 09:09

kamens