This is a fragment from the book “Beginning Javacript 5th edition”.
Chapter X :
JavaScript is a powerful language, and a lot of that power comes from functions. Unlike many other languages, functions are rst‐class citizens in JavaScript; in other words, we can treat functions
just like any other type of value:
[CODE]function convertToCentigrade(degFahren) { var degCent = 5/9 * (degFahren – 32);
return degCent; }
var myFunction = convertToCentigrade;
This code assigns the
[CODE]convertToCentigrade()
function to the
[CODE]myFunction
variable, but look closely at the right‐hand side of the assignment.This means that we now have two ways of executing the same function. We can call it normally by executing convertToCentigrade(), or we can execute myFunction(), like this:
[CODE]
var degCent = myFunction(75); // 23.88888889
var degCent2 = convertToCentigrade(75); // 23.88888889
What is the purpose of this handling?
What would be ideal/convenient situations for using the functions like that?
Thanks in advance!
Bruno.