JS Course 1: Fundamental 3 Flashcards
What are functions useful for?
Functions are useful for achieving a single task without needing to rewrite the code to run a task over and over again.
What’s the difference between functions and methods?
Functions are a set of instructions th perform a single task and do not associate with methods.
Methods are like functions, but they specifically only associate with objects.
What are function parameters? What are optional parameters and default parameters?
Function parameters, or arguments, are values you apply to a function when invoking them. They are values needed to be included inside the function’s parentheses to do it’s job properly.
Optional parameters are function parameters that are not required for the function to run, but can be applied if needed.
Default parameters are function parameters that have preset/default settings or values (unless they’re reassigned.)
What are function arguments?
Function arguments, compared to function parameters, are the actual values passed through a function. Function parameters are the variables or other values to be used in the function, but function arguments are the actual values you pass into a function.
How do you invoke a function?
You invoke a function by calling the name in arguments or applying the function to a variable
Examples:
prompt(“You’re stupid”)
or
variable.Boolean()
What is function scope?
Function scope refers to the scope of variables that can only be seen inside a function.
What is Global Scope?
Global Scope refers to the variables that are retrievable on the outside of functions. In other words, everywhere on the page except for inside functions.
What are Local Variables
Local variables are variables inside a function that are inaccessible to the global scope.
What are Outer Variables?
Outer variables are variables that can be retrieved by functions outside of those functions, also called Global Variables.
What are return values?
Return values are the values returned after running a function.
What are anonymous functions?
Anonymous functions are functions that do not have a name. This is done with the syntax of function expression.
Syntax:
(function () {
alert(‘hello’);
})
What are arrow functions?
Arrow functions are functions created with an alternative, more compact syntax using the arrow symbol =>.
What are custom functions?
Custom functions are functions you can customize in your code. You can customize the job it does and the name of the function.
What is function declaration?
Function declaration is a way to create a function.
Syntax:
function myFunction() {
alert(‘hello’);
}
What is function expression?
Function expression is a way to create a function.
Syntax:
let sayHi = function() {
alert( “Hello” );
};