Printing to the console is nice but can only get you so far. This week I will discuss the use of variables and functions in Hack. Now many of you who have been following along with my blog know that I have made a few comparisons from PHP to Hack in their similarities today we will explore one of thier differences.
Before we get into things I thought I’d show you how to setup the Hip Hop Virtual Machine (HHVM) as a local web server using the terminal.

Now that we got that out of the way let’s discuss variables in Hack.. A ‘$’ symbol must be used to define a variable. Such that $x = 5, would initialize the variable x with a value of 5. If we want to use we reference the variable x ,$ is just used to define the variable.
Don’t forget the semicolon !!!
Now that we understand how variables work in Hack let’s talk about functions. Unlike PHP, Hack functions can have specified return types. If these functions have parameters defined then you must define the datatype in the declaration of the function. Every function declaration starts with the keyword “function” followed by the name a list of parameters. If you want specify a return type for the function then type “:[datatype]”. This really handy if you have some complex object in which you wish to return.



