javascript 中的 === 是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3553534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 05:09:41  来源:igfitidea点击:

What is === in javascript?

javascript

提问by viksit

Possible Duplicate:
Javascript === vs == : Does it matter which “equal” operator I use?

可能的重复:
Javascript === vs ==:我使用哪个“相等”运算符重要吗?

Looking into the answer of Chris Brandsmain Advanced JavaScript Interview Questionswhat is ===in Javascript.

查看Chris BrandsmaAdvanced JavaScript Interview Questionswhat is ===in Javascript 中的回答。

If possible please provide a simple example

如果可能,请提供一个简单的例子

回答by viksit

=== is the strict equal operator. It only returns a Boolean True if both the operands are equal and of the same type. If a is 2, and b is 4,

=== 是严格的相等运算符。如果两个操作数相等且类型相同,它仅返回布尔值 True。如果a是2,b是4,

a === 2 (True)
b === 4 (True)
a === '2' (False)

vs True for all of the following,

对以下所有情况都为真,

a == 2 
a == "2"
2 == '2' 

回答by rubayeet

=== is 'strict equal operator'. It returns true if both the operands are equal AND are of same type.

=== 是“严格相等运算符”。如果两个操作数相等且类型相同,则返回 true

a = 2
b = '2'
a == b //returns True
a === b //returns False

take a look at this tutorial

看看这个教程

回答by Rakesh Goyal