Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have this condition in Javascript:

const isObject = (typeof item.data.data[field] == "object" || typeof masterRecord.data.data[field] == "object") && item.data.data[field] != null;

If I use Chrome devTools to step through the code, isObject resolves as true, but this is not correct.

If I insert a breakpoint at the specific line and break down the conditions into its parts, I get the following values:

  • typeof item.data.data[field] == "object" -> false
  • typeof masterRecord.data.data[field] == "object" -> false
  • (typeof item.data.data[field] == "object" || typeof masterRecord.data.data[field] == "object") -> false
  • item.data.data[field] != null -> true

...and finally, the condition as a whole, with its correct output:

  • (typeof item.data.data[field] == "object" || typeof masterRecord.data.data[field] == "object") && item.data.data[field] != null -> false

Ideas?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
137 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...