how to define a function with parameters in html and js code example
Example 1: javascript function
var num1;
var num2;
function newFunction(num1, num2){
return num1 * num2;
}
Example 2: pass function as argument typescript
class Foo {
save(callback: (n: number) => any) : void {
callback(42);
}
}
var foo = new Foo();
var strCallback = (result: string) : void => {
alert(result);
}
var numCallback = (result: number) : void => {
alert(result.toString());
}
foo.save(strCallback);
foo.save(numCallback);