Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

javascript - 为什么true || 1 === 1/3在JavaScript中返回true(Why does true ||1 === 1/3 returns true in JavaScript)

I know that === operator used to determine whether its both operands are equal and identical or not.(我知道===运算符用于确定其两个操作数是否相等且相同。)

That is to say that if left side operand has 1 then the right side operand must be 1 for returning true .(也就是说,如果左侧操作数为1,则右侧操作数必须为1才能返回true 。) but I don't get why javascript returns true for this calculation.(但我不明白为什么javascript对于此计算返回true。)
true || 1 === 1/3;

//true;

I don't get how this result can be true in javascript.(我不知道如何在javascript中实现此结果。)

  ask by Ami Nirob translate from so

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

1 Reply

0 votes
by (71.8m points)

The === Operation will never be checked.(===操作将永远不会被检查。)

The statement is true by true .(该声明是真实的true 。)

Also see this question and answer on how if statements are evaluated.(另请参阅问题和答案,了解如何评估语句。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...