New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New tip for jstips - Improve Nested Conditionals #3
Conversation
New tip for jstips - Improve Nested Conditionals
Using |
Thanks you for your point padsbanger, I know it's not appropriate to use switch on javascript and the problems associated with its use, I'm trying to convey the steps to improve nested if and nested if with several checks in each statement. Maybe I should add the problems associated with the use of switch. |
In line with this, I remember that Eric Elliot retracted his advice about not using switch statements https://twitter.com/_ericelliott/status/673011325568610305 |
@AlbertoFuente hey nice tip, it's true the switch is not a good pattern but you can explain it. |
}; | ||
|
||
if (color) { | ||
colorObj[color](); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be a good idea to check
colorObj.hasOwnProperty(color)
before we use.
@loverajoel Ok, I will improve it, and thank you for this great initiative. 👍 |
Check if colorObj.hasOwnProperty(color) inside conditional statement. Improvement proposed by @manmadareddy
switch(!!color) {
case (typeof color != 'string'): break;
case (color == 'blue'): console.log('Blue') break;
case (color == 'green'): console.log('Green') break;
} |
we want more jstips!!! one jstip a day keps bugs away! |
Thanks for improvement @noncentz. |
@AlbertoFuente the contributions guidelines changed, and the new tips will be at the top of the list. |
I've already put the tip above the others, I have a question, I see different types of numbering for tips: 0 - Insert ...1 - angularjs ...02 - ReactJs ...It would be nice to specify a standard for numbering the tips. |
@AlbertoFuente awesome! the tips numbering should be 00, 01, 02, 03... I made a mistake with the previous two and now I can't fix because the tweets are going to lost the link(works with the title). Thanks man |
I'm having troubles with the squash |
@AlbertoFuente this is a good article about squash commits. |
Thank you very much, there's something I'm not doing well. |
@AlbertoFuente don't worry, thanks for your tip! |
New tip for jstips - Improve Nested Conditionals
…g example Fixes/improves loverajoel#66
Update Tip #3 Improve Nested Conditionals with a refactoring example
No description provided.