Function Declarations

Welcome to our free Advanced JavaScript Programming tutorial. This tutorial is based on Webucator's Advanced JavaScript Programming course.

Contact Us or call 1-877-932-8228
Function Declarations

Function Declarations

Perhaps the most basic manner in which we can create functions in JavaScript is with a function declaration, often called a function statement. It's the way in which most of us first learn about functions and perhaps the most familiar:

function foo(bar) {
	return bar + 3;

Here we defined a function named foo which accepts a parameter bar and returns the value of bar plus three. We can call our foo function later


to write, in the example above, the value 12 to the screen. Because function declarations are hoisted - moved by the JavaScript interpreter to the top of the executing code and evaluated before execution flow - we could even invoke our function foo before declaring it. (This is true for variable declarations in JavaScript, too. Many developers suggest not relying on this feature but rather, for clarity and code organization, declaring variables and functions before they are used.)


This tutorial is based on Webucator's Advanced JavaScript Programming Course. We also offer many other JavaScript Training courses. Sign up today to get help from a live instructor.