Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Expressions Vs. Statements in Functional Programming

Hello All! I'm trying to learn more about the difference between the Imperative and Functional programming languages, since JavaScript is functional and I am not very familiar with it.

I think it comes down to the difference between expressions in programming and statements in programming. Can someone try to relate these concepts back to JavaScript specifically so I can learn about the paradigm? Or even suggest some resources to look up?

Thanks!

1 Answer

Javascript is "sort of" a functional programming language. Here's a definition that is a mouthful.

"JavaScript, often abbreviated as JS, is a high-level, dynamic, weakly typed, prototype-based, multi-paradigm, and interpreted programming language.

...As a multi-paradigm language, JavaScript supports event-driven, functional, and imperative (including object-oriented and prototype-based) programming styles. It has an API for working with text, arrays, dates, regular expressions, and basic manipulation of the DOM, but the language itself does not include any I/O, such as networking, storage, or graphics facilities, relying for these upon the host environment in which it is embedded." (emphasis added)

https://en.wikipedia.org/wiki/JavaScript

"In computer science, functional programming is a programming paradigmโ€”a style of building the structure and elements of computer programsโ€”that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. It is a declarative programming paradigm, which means programming is done with expressions[1] or declarations[2] instead of statements."

https://en.wikipedia.org/wiki/Functional_programming

"JavaScript distinguishes expressions and statements. An expression produces a value and can be written wherever a value is expected, for example as an argument in a function call... ...Roughly, a statement performs an action. Loops and if statements are examples of statements. A program is basically a sequence of statements. " http://2ality.com/2012/09/expressions-vs-statements.html

Good luck!