Advertisement
sissou123

Untitled

Mar 18th, 2022
1,042
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. JavaScript Algorithms and Data Structures
  2. Basic JavaScript
  3. Explore Differences Between the var and let Keywords
  4. One of the biggest problems with declaring variables with the var keyword is that you can easily overwrite variable declarations:
  5.  
  6. var camper = "James";
  7. var camper = "David";
  8. console.log(camper);
  9. In the code above, the camper variable is originally declared as James, and is then overridden to be David. The console then displays the string David.
  10.  
  11. In a small application, you might not run into this type of problem. But as your codebase becomes larger, you might accidentally overwrite a variable that you did not intend to. Because this behavior does not throw an error, searching for and fixing bugs becomes more difficult.
  12.  
  13. A keyword called let was introduced in ES6, a major update to JavaScript, to solve this potential issue with the var keyword. You'll learn about other ES6 features in later challenges.
  14.  
  15. If you replace var with let in the code above, it results in an error:
  16.  
  17. let camper = "James";
  18. let camper = "David";
  19. for more: https://www.clictune.com/ex79
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement