What are some functions that we know?
prompt("number please...");
console.log("hi");
parseInt("5");
Syntax:
function functionName(param1, param2) {
Some statement(s) here;
}
Here’s a bare bones function….
function foo() {
console.log("FOO!");
}
What does this function do and how would you execute (call) it?→
To create a function that has an input, and executes some code…
function foo(s) {
console.log(s + "!");
}
How does this improve on the previous example?→
How would you call this function, using it to print "Hello world!" to the console?→
To create a function that has an inputs, and returns a value….
function foo(s) {
return s + "!";
}
console.log(foo("hi"));
How does this differ from the previous example?→
You can use a function as you would use a variable…
// as part of an expression
var sum = someNum + calcSomething(x);
// in a function call
console.log(calcGrade(num));
// inside another function
function calcGrade(x) {
return someNum + calcNum(y);
}
How does this differ from the previous example?→