URL shortening API landing page using SASS and JavaScript
Design comparison
Solution retrospective
Hello everyone, if there are any suggestions or improvements i can do, Please let me know and i'll be very appreciate for your feedbacks.
- I need your feedbacks about my
JavaScript
code:- It is ok to be that long..!
- Is the logic ok..!
- Are there anything need to be improved ?
Have a good day everyone^^ THANKS^^
Community feedback
- @ohCyrusPosted over 2 years ago
You could make your code more readable by using guarding clause in JavaScript. It will avoid nested if ... else statements and makes code cleaner to read in a function.
function exampleFunction(arg) { if (!arg > someExpressionHere) return; // ... Do something otherwise }
In my opinion, a function should only do 1 thing. And it's better than 1 function that do all the work. By splitting up functions in parts, it will make the project more easier to maintain than your current code. Avoid also NESTED functions.
Just write it out in the global scope so other function can reuse it. Or simply use ES6 classes if you like structured code š Example on nested fns:
function doSomething(arg, arg2) { // ... // Nested function anotherFunction(arg) { // ... Do something } }
Instead:
// Pass in all required args for the function to work function anotherFunction(arg, arg) { // ... Do something } function doSomething(arg, arg2) { // ... // Pass in required arguments anotherFunction(arg, arg2); }
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord