Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Bad
- function foo (obj) {
- let result;
- if (typeof obj === 'object' && obj.hasOwnProperty('value')) {
- let data = getData(obj.value);
- if (data.foo) {
- result = convert(data.foo);
- } else {
- result = null;
- }
- }
- return result;
- }
- // Good
- function foo (obj) {
- if (typeof obj !== 'object' || !obj.hasOwnProperty('value')) {
- return null;
- }
- let data = getData(obj.value);
- if (!data.foo) {
- return null;
- }
- return convert(data.foo);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement