Global Variables and Function Parameters


#1

Let’s say we have the code:
const satellite = ‘The Moon’;
const galaxy = ‘The Milky Way’;
let stars = ‘North Star’;

const myNightSky = () =>
{
return 'Night Sky: ’ + satellite + ’ , ’ + stars + ’ , ’ + galaxy;
};

console.log(myNightSky());

My main problem is that I fail to understand why myNightSky is able to execute at all. After all, myNightSky does not explicitly include any parameters in the parantheses. Yet, satellite, stars, and galaxy are returned. How is it possible to have a function with no explicitly specified parameters return global variables?


#2

Function don’t need parameters? Parameter are optionally

that is why they are called global variable, they are global and can be accessed by any part of the program (including inside a function)


#3

Did you set the variable ‘satellite’ equal to ‘The Moon’?

This is an error message i get in multiple browsers… i made a separate post but no one has responded just yet…

my code is correct, but for some odd reason I cannot proceed past the first step of the instructions for the lesson


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.