Advertisement
karlakmkj

Block scope

Dec 9th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const logVisibleLightWaves = () => {
  2.   let lightWaves = 'Moonlight';
  3.   let region = 'The Arctic';
  4.  
  5.   // Add if statement here:
  6.   if (region === 'The Arctic'){
  7.     let lightWaves = 'Northern Lights';   //let keyword is used, so it will not overwrite the value Moonlight
  8.     console.log(lightWaves)  //prints Northern Lights
  9.   }
  10.   console.log(lightWaves);   //prints Moonlight
  11.  
  12. };
  13.  
  14. logVisibleLightWaves(); //call the function above
  15.  
  16. console.log(lightWaves); //However if want to print the variable that is local (block scope) for both values, then it will prompt error as it cannot be accessed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement