By forgetting to add the return statement to
our function we end up returning
undefined from our function as a result.
return "TV show aired in: " + year;
EX1
TV show aired in: 1990
The return statement stops the execution
string
of the function and sends back a value to
the caller.
function displayAirDate(year) {
return "TV show aired in: " + year;
There are other copies of this card
function displayAirDate(year)
}
const text = displayAirDate(1990);
1990
console.log(text);
function moreThanTen(number) {
Console output
return number > 10;
}
const text = displayAirDate(1990);
true
1.
const result = moreThanTen (14);
console.log(text);
The function displayAirDate
correctly concatenates the string
with the year
console.log(result);
2.
The return statement in the
function displayAirDate constructs
and returns the string TV show aired
In this case, it returns whether the number
in: 1990 ,
is greater than 10.
a.
function displayAirDate(year) {
return "TV show aired in: " + year;
}
which is then stored in the
text variable and logged to the
const text = displayAirDate(1990);
console.log(text);
console.
Return the variable from this function
Variable
The variable name is the the left of the const keyword
There are other copies of this card
So to return the variable from this function:
function getBrightness() {
function getBrightness(brightness) {
}
return brightness
return brightness;
Return variable
const brightness = 67;
return brightness;
}
console.log(getBrightness());
console.log(getBrightness());
Console output
67
The function correctly returns the brightness variable.
The return statement return brightness; sends the value of the variable
brightness (67) back to where the function getBrightness was called. This
value is then printed by console.log .
Console output
67
function getBrightness(const brightness = 67){
}