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.
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.
"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 bycase
s instead, and the second uses assignment inside the conditional operator, which is very confusing.– CertainPerformance
Aug 23 at 0:44