Functions Flashcards
function showMessage() {
alert( ‘Hello everyone!’ );
}
function deceleration or expression?
deceleration
let userName = ‘John’;
function showMessage() {
let message = ‘Hello, ‘ + userName;
alert(message);
}
showMessage(); // returns and why?
Hello, John
A variable declared inside a function is only visible inside that function.
function showMessage() {
let message = “Hello, I’m JavaScript!”;
alert( message );
}
showMessage(); // returns? and why
alert( message ); // returns? and why?
Hello, I’m JavaScript!
variable in function
<– Error! The variable is local to the function
variable not accessible to function.
A function can access an outer variable as well,
True or False
True
let userName = ‘John’;
function showMessage() {
let message = userName;
alert(message);
}
showMessage(); // returns and why?
John
A function can access an outer variable.
a function can access and alter a outer variable?
True or False
True
let userName = ‘John’;
function showMessage() {
userName = “Bob”;
let message = ‘Hello, ‘ + userName;
alert(message);
}
alert( userName ); // returns?
showMessage();
alert( userName ); // returns?
John
before the function call
Bob,
the value was modified by the function
In a function the outer variable is only used if ______
there’s no local one.
let userName = ‘John’;
function showMessage() {
let userName = “Bob”;
let message = userName;
alert(message);
}
showMessage(); // returns and why?
alert( userName ); // returns and why?
Bob
the function will create and use its own userName
John,
unchanged, the function did not access the outer variable
Variables declared outside of any function, such as the outer userName in the code above, are called _______
global
Global variables are visible from any function unless_____
shadowed by locals
_____ variables are visible from any function
Global
A ______ is the variable listed inside the parentheses in the function declaration
parameter
An ________ is the value that is passed to the function when it is called
argument
If a function is called, but an argument is not provided, then the corresponding value becomes __________.
undefined