Stop Using If Else And Switch Statement in Javascript Except do this

preview_player
Показать описание
#JavaScriptFeatures #JavaScriptTutorial

In this video I'm gonna talk to you about if else statement in JavaScript I will tell you an alternative of that which will help to reduce messy code.

⭐ ⭐ ⭐ ⭐ ⭐ Best Books for JavaScript: ⭐ ⭐ ⭐ ⭐ ⭐

⭐ ⭐ ⭐ ⭐ ⭐ ⭐ My Gear ⭐ ⭐ ⭐ ⭐ ⭐ ⭐

Комментарии
Автор

I've been doing a similar thing with arrays for years. For example, check this code (Not really necessary. Just for demonstration purposes):

function monthName(monthNum, abbrevLength = 9) {
let monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
return monthNames[monthNum].slice(0, abbrevLenth);
}

caribbeanman
Автор

Please guys don't try to be smart. This will work if the requirements are at the KG1 level. Once you reach level 1 then it won't work.

TarekFaham
Автор

Totally wrong, There are tons of logical and math cases which in the Object literal can not serve. Your video act like depricating the SWITCH & and the IF/Else .. You are misguiding any beginner watches your video.

AliBorsan
Автор

it would be even better to keep the obj outside of the function to avoid its creating each time when the function is called

artyomboyko
Автор

How come is this the first time I am seeing this 😂 Thank you!

monkeyofjp
Автор

I like it but it doesn't quite fit with a redux reducer. Maybe I'm mistaken though

kettenbach
Автор

Awais, there are a few typo mistakes in your video, as people in the comments are pointing out as well, maybe to redo it? Your lower function getTrasnlateMap should be getTranslateMap, its trivial but still... and of course the: return obj[ ...] instead of obs
thank you otherwise! Very new and informative

chantingdroneflutes
Автор

How does it different from return obj[x.toLowerCase()] || "x not found";

srinik
Автор

Do you return 'obs' or 'obj', on last example?

edo