Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMoses Finlay
Full Stack JavaScript Techdegree Graduate 24,800 PointsIs there a difference between two these functions?
$greet = function() {
};
function greet() {
}
4 Answers
Alexander Davison
65,469 PointsNope :)
magicnerd
16,208 PointsI'm not sure but I think there is. In the first example you set the variable $greet to be the specified function. In the second example you simply create a function greet().
In the case of the first example where you set it as a variable, you can later (or earlier in your code) change that variable to be something completely different than the function. Such as for example, another function or a new integer, etc.
In the second example there is no variable, only a set function called greet() which can not be changed unless you change the code of the function itself.
That is one difference...
Alexander Davison
65,469 PointsWhat do you mean?
Moses Finlay
Full Stack JavaScript Techdegree Graduate 24,800 Points$greet = function() {
};
Starts off with a variable, then the function ends with the a semicolon. Is there a different way to call
$greet = function() {
echo '?';
};