How do I declare a more global variable that overrides a previous global variable?


#1

const satellite = 'The Moon';
const galaxy = 'The Milky Way';

let stars = 'North Star';

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

console.log(myNightSky());
consol.log(stars);

I am specifically talking about the syntax for the last consol.log(stars)

Hoping to help the other members by asking this too!

Here is the link:
Stars-Global-over-Global


#2

global means everywhere. There’s no such thing as “more everywhere”.
You can create scopes (functions) within other scopes though, so you can always make something less global (local)

Not sure what this has to do with syntax or your code though, so if there’s something you wonder about your code, you’ll need to describe what you want to accomplish and what’s stopping you.

Not a syntax issue, but one of names: I would compare the last two lines with each other closely, one of them refers to something that hasn’t been defined.


#3

Simple spelling mistake! I figured it out.


#4

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