Functions
List all the functions you already know (hint: anything with
()
at the end)prompt
,console.log
,document.getElementById
,parseInt
,array.toUpperCase
Part of the magic of programming is reuse! You can write your own functions and then use them many times.
What happens if...?
I don't call the function at all?
I forget the
()
?I call the function before defining it?
Parameters and return values
Function parameters + return values
Extend this example:
If no parameter is passed in, return
ARRRGHHH!!!
instead.
Let's do another example:
What happens if...
I don't have a
return
at all in the function?I try to
console.log(num1)
outside the function? After the function? After the function is called?What if I use
const
orlet
to create a variable inside the function?How many parameters can I have?
What happens if I put some code after the
return
?How do I return multiple bits of information?
References
Last updated
Was this helpful?