why function datatype i.e. function foo() : int {

I just found an answer on the forum where the guy defines the data type for a function, and returns a value at the end of the function,it goes like this:

function MaxValue (intArray : int[]) : int {
    var max = intArray[0];
    for (i = 1; i < intArray.Length; i++) {
       if (intArray *> max) {*

max = intArray*;*
return max;
what is the point in declaring the function datatype? is it related to the return command at the end of the function?

Efficiency. As you say, it is specifying what sort of value will be returned when the function completes. Javascript, out of the box, will let you return any data type you like or none at all. The following is an example of valid code:

var value : int;

function Billy() {

    if (0 == value){
        // returns a string
        return "fish";
    }else if (1 == value){
        // returns an int
        return 42;
        // return nothing at all

Absolutely nothing wrong with such code without the constraint that you’ve highlighted. However, if you can be more specific about the type of data you plan to return then the compiler warn you if you’ve made a mistake in the value you return and that can save you valuable time. We’re all human and can benefit from checks of one form or another.

The point of specifying a type for a function is the same as specifying the type for a variable: it “locks in” the type, thereby preventing the compiler from inferring it. While this doesn’t change the actual compiled code in any way, it can prevent coding errors resulting from accidentally returning the wrong type, and can potentially make the code easier to follow.