Want to know which one is better javascript design & clean code as per javascript experts

Want to know which one is better javascript design & clean code as per javascript experts


switch (cloudType)
case "aws":
value = (updateDefaultInfo) ? this._resetMessageDefaultValues.aws = defaultValue : this._resetMessageDefaultValues.aws;
resetText = this._messages.current.aws
break;
case "vsphere_on_prem":
value = (updateDefaultInfo) ? this._resetMessageDefaultValues.private = defaultValue : this._resetMessageDefaultValues.private;
resetText = this._messages.current.private
break;
case "azure":
value = (updateDefaultInfo) ? this._resetMessageDefaultValues.azure = defaultValue : this._resetMessageDefaultValues.azure;
resetText = this._messages.current.azure
break;



Or


value = (updateDefaultInfo) ? this._resetMessageDefaultValues[cloudType] = defaultValue : this._resetMessageDefaultValues[cloudType];
resetText = this._messages.current[cloudType]



I am new to javascript world and wanted to learn and design things in better manner.





"Clean code" is somewhat opinion-based, you might try codereview instead (and probably post more of your code). Neither snippet looks good to me IMO, the first uses switch when it should probably use an object indexed by cases instead, and the second uses assignment inside the conditional operator, which is very confusing.
– CertainPerformance
Aug 23 at 0:44



switch


case





Can you please give me one example how I can use object indexed by cases here?
– Gautam
Aug 23 at 1:00





The question asks for opinion, which is offtopic. But neither of them. Long ternary expressions are unreadable. Why does the question have angular tag? Are you using Angular or React? Because Angular defaults to TypeScript, and things may be different in JS and TS because of type safety.
– estus
Aug 23 at 1:37










By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)