Freemarker doesn't provide a scope mechanism like JavaScript. But it does feature macros and locals. Here's a bit of code I used for playing around with macros and locals.
Requires maven in order to compile and run
Start the webserver with
mvn jetty:run
and point your webserver to
http://localhost:8080/freemarker-testing/test.ftl