JavaScript functions Flashcards
What is function in JavaScript?
a group of reusable code that you can use anywhere in the code.
Give at least one benefit of JavaScript function.
It reduces repetition of code within a program. It becomes easier to eliminate the errors.
Why do you need to call a function?
Because a defined function does not execute automatically. A function only specifies what to do when we execute the function.
What is a parameter in a function?
used inside a parenthesis in a function declaration. It takes the value of what the function arguments contain and work with them entirely of the function.
The lifetime of parameters is only inside the function. True or false?
True.
We can pass up to 25 parameters, separated by commas. True or false?
False. We can pass up to 255 parameters, separated by commas.
What is the difference of a parameter and an argument?
Arguments are the actual values that we pass to a function at the time of function call.
The names of a parameter and an argument cannot be the same. True or false?
False. It can be the same or different, depends on your preference.
Function return. A function can return a value back to the script that called the function by using the return statement. True or false?
True.
What is local scope?
A local scope variable is a variable that can only be used inside the function.
Global scope can only be used inside the function. True or false?
False. It can be used in a function and outside the function.
A variable that has not been declared will automatically become local scope. True or false?
False. It automatically becomes global scope.