What is the purpose of the var command when used in the function statement?

Asked

Viewed 38 times

1

In Javascript it is possible to write functions with or without the use of the keyword var, see below two functions that illustrate this situation:

var soma = function(a, b) {
    return a + b;
}

window.alert("Soma de 10 + 5 eh igual a: " + soma(10, 5));

subtrai = function(a, b) {
    return a - b;
}

window.alert("Subtracao de 20 - 10 eh igual a: " + subtrai(20, 10));

Note that the function soma() uses the keyword var and the function subtrai() does not use it. Therefore, I would like to know what is the purpose of using the keyword var when it is used in job statements and whether the use of it or not implies something?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.