Defining Functions
You define a function by using the function
keyword followed by a name that describes the use of the function, a list of zero or more arguments in ()
, and a block of one or more code statements in {}
. For example, the following is a function definition that writes "Hello World"
to the console:
function myFunction(){ console.log("Hello World");}
To execute the code in myFunction()
, all you need to do is add the following line to the main JavaScript or inside another function:
myFunction();
Get Learning AngularJS now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.