Understanding functions Flashcards
Why are functions like black boxes?
Because we can use them without knowing the code inside of them
How do we decide a function’s input?
Based on the output we want
What happens when we pass the wrong type of value to a function?
The function won’t work as intended
What happens when a function’s input is a different type than the output?
The function works, the input type can be different to the output type
What can be considered as output?
What a function displays in the console or what it returns
When does a variable have a local scope?
when we create it inside of a functions block
What does it mean for a variable to have a local scope?
We can’t access or update it outside of the function where it was created
What happens when we try to access a local scope variable outside of the function that created it?
We get an error
Variables created outside of a function block have a _________ scope
Global
Which variables have a global scope?
Variables created outside the function block
From where can we access a variable with a global scope?
from anywhere in the code
From where can we access a variable with a global scope?
from anywhere in the code
What kind of scope do variables created inside conditionals and loops have?
Local
When can we first access a variable, regardless of scope?
Only after we create it