Functions as per your course



I was a little confused in your parts about functions in seeing them defined as:
const functionName = (parameter) => {}

having been used to

function functionName(parameters){} in all my programming background and with my understanding of JavaScript.

My confusion lay in the idea that a function output is never constant as its output is always variable dependent upon the parameters. However, the function itself is constant so hence the confusion and the output is only a part of the constant function.

However, I see when searching for your method lengthy discussions about the need for JavaScript to have the same orthodoxy as C++ for example, something which I can relate to even though I come from a VB background. Some of these discussions go so far as recommending this be approached to the W3C/TC-39 committee.

Therefore, my questions are this and please pardon my ignorance as it is huge.

  1. Have you gone down this path in the assumption or knowledge that the definition of a function will be changing within JavaScript to align it more closely to the pure C type languages?
  2. Does this also relate to ECMA script 6 (something which I am also absolutely ignorant about)?


const pi = +Math.PI.toFixed(4);

We can no longer redefine this variable. It is constant and immutable during the session.

In vanilla JS is possible to re-use a function name as a variable, effectively wiping out the function.

 > function foo() {}
<- undefined
 > foo()
<- undefined
 > foo = 42
<- 42
 > foo()
! TypeError: foo is not a function

See how easy it was for our program to overwrite that function? const is how we stop that from being possible.

 > const foo = function () {};
<- undefined
 > foo = 42
! TypeError: invalid assignment to const `foo'

As to your two questions, you’ll need to dig up some white papers. Clearly, though, ECMA 2015 shook a few trees. The first major rewite of JS in nearly a decade. And how many revisions have cropped up since? Whether the goal is to be more C like or just more functional your reading will disclose.

Arrow functions look to be stateless and they have no baggage (this, arguments, etc.) so when deployed with pure functional intent are light weight vehicles.


Thanks for your quick response, it is appreciated and has given me more to go on and some much needed background. I didn’t realise that it was possible to reuse a function name in JavaScript as that in my opinion could be very dangerous as you have demonstrated .

Do I now close this or just let it close after the 7 day period?


You let it close after the seven day period would be the norm, and without marking your own post as the solution, I might add.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.