Named Functions

Also called a function statement.
This always starts with the keyword "function".
You do not have to put a semicolon at the end of the function declaration.


Without Arguments

function doSomething() { 
   alert('my message');
}

doSomething();


With Arguments


This declares a function called Function_Name1 in the current scope that takes one argument.

function Function_Name1(parameter1) { 
   // a set of statements
}

This function takes 2 parameters

function Function_Name2(parameter1, parameter2) { 
   // a set of statements
}
var sum = Function_Name2(1,2)

Regular functions play nicer with Stack call trace.



© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext