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

Categories

0 votes
134 views
in Technique[技术] by (71.8m points)

javascript - Condition not resolving correctly

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?


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

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...