@AngeliqueDF
Posted
Hi! I think you did great on this, the end result looks great!
For the JavaScript code, I don't think it was an issue to declare global variables like you did because this project is very small. However I think in this case it's risky to declare your variables with the let
keyword instead of const
.
Marked as helpful
@AbdulkerimAwad
Posted
@AngeliqueDF can I know what are the problems may I encounter by using let instead of const, and what is the way to wrap the vars in big projects?
@AngeliqueDF
Posted
@AbdulkerimAwad The let
keyword allows you to redefine variables which is what we want sometimes. But in this case you have selected DOM elements. If you or another developer redefines them by mistake during development it could lead to bugs.
I've seen people recommend using const
most times, and let
only when you're sure the variable will change. I follow this advice, and so far I think it helped.
One way you could wrap the variables is by defining classes with private fields, or external modules. I invite you to search "javascript design patterns" on Google, there are many patterns you can use in your code.
I actually used the same project to learn about this, check my solution (https://github.com/AngeliqueDF/manage-landing-page/tree/main/src/js). I tried using the module design pattern for the slider.
Marked as helpful
@AbdulkerimAwad
Posted
@AngeliqueDF Thanks so much that's was very useful
@AngeliqueDF
Posted
@AbdulkerimAwad You're welcome!