Star (-) Watch (-)

Learn Javascript

Declaring Functions

Functions, like variables, must be declared. Let's declare a function double which accepts an argument called x and returns the double of x :

function double(x) {
    return 2 * x;
}

Functions are also values in JavaScript: they can be stored in variables (just like numbers, strings, etc ...) and given to other functions as arguments :

var double = function(x) {
    return 2 * x;
};

Exercise

Correct!
False!

Declare a function named triple that takes an argument and returns its triple.

⌂ Proxy