My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Scope confusion in javascript

Default profile photo
Anonymous
·Mar 6, 2018

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());
console.log(stars);

Here Inside function(myNightSky) when I am writing let before stars then I am getting 'North Star' while logging stars(console.log(stars)) ,but without writing let before the variable star in the function myNightSky I am getting the value Sirius.

I am not understanding what is going under the hood.