JavaScript: What Are FunctionsThe most basic purpose of a
function is to contain code. In JavaScript, we do not have to define the
function before we use it The code for a function MUST be contained by curly brackets { }, even if the code is only one line. So, function hello() document.write(\\\\'Hello\\\\'); is not legal JavaScript, although it looks like it should be.
A function\\\\'s advanced features are that it can take parameters and return values. Take parameters means that we can pass
variables to a function for the function to work on. Functions have another quirk, which is that
they can house local variables. A
local variable is a variable that cannot be seen outside its scope, and behaves
independently from other variables of the same name. |