Skip to content

Instantly share code, notes, and snippets.

@monstaro
Last active July 30, 2019 17:55
Show Gist options
  • Save monstaro/af0f4f091879b727da079d1bc11cc3dd to your computer and use it in GitHub Desktop.
Save monstaro/af0f4f091879b727da079d1bc11cc3dd to your computer and use it in GitHub Desktop.
Session 5
If we have a function defined as function sayHello(){console.log("Hello!")}, what is the difference between entering sayHello and sayHello() in the console?
When you type the function defined with parenthesis, it just returns undefined. If you do not include parenthesis, it is returned as a syntax error.
What is the difference between function parameters and arguments?
Parameters indicate what information a function needs to know in order to work (ex. width, height)
Arguments use the return value of the parameters and pass it along into the code.
What is the keyword return used for?
The return keyword returns a value to the code that called the function.
How are local variables better than global variables? Are there instances you can think of where you might want to use a variable that is globally scoped over local?
Local variables are better than global variables because they take up less memory. Since local variables are removed once the functions task is finished,
the variable can have different values. Different functions can use variables with the same without conflict, as well.
If you need multiple functions to access the same variable, you may want to use global variables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment