日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

javascript运算符_JavaScript中!=或!==运算符之间的区别

發(fā)布時(shí)間:2023/12/1 javascript 59 豆豆
生活随笔 收集整理的這篇文章主要介紹了 javascript运算符_JavaScript中!=或!==运算符之间的区别 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

javascript運(yùn)算符

We can perceive the differences between these two operators as the same difference that occurs between double equalsTo (==) and triple equalsTo (===) operators. We already know that the (!) not-operator used along with (=) operator is used to check for inequalities.

我們可以將這兩個(gè)運(yùn)算符之間的差異視為與double equalsTo(==)和Triple equalsTo(===)運(yùn)算符之間相同的差異。 我們已經(jīng)知道與(=)運(yùn)算符一起使用的(!)非運(yùn)算符用于檢查不等式。

let a = 10; let b = 20;console.log(a != b);

Output

輸出量

true

Since both a and b hold different values, we get a truthy returned from the inequality.

由于a和b都具有不同的值,所以我們從不等式中得到了真實(shí)的結(jié)論。

let c = 50; let d = 50;console.log(c!=d);

Output

輸出量

false

And of course in the above case since both have the same values != operator returns false. Therefore we can say that the != operator checks if the two variables being compared have the same value or hold the same value. If they don't, it returns true and false otherwise as we have seen in the above two examples.

當(dāng)然,在上述情況下,因?yàn)閮烧叨季哂?strong>相同的值!=運(yùn)算符將返回false 。 因此,可以說!=運(yùn)算符檢查要比較的兩個(gè)變量是否具有相同的值或具有相同的值。 如果沒有,則返回true和false,否則如上面兩個(gè)示例所示。

let s = 101011; let name = "sam";console.log(s != name); console.log(s !== name);

Output

輸出量

true true

We have compared two variables which are completely different type storing the same values and we get truthy for both the comparison expressions. Now, look at the next example:

我們已經(jīng)比較了兩個(gè)完全不同的變量,它們存儲(chǔ)相同的值,并且兩個(gè)比較表達(dá)式都正確。 現(xiàn)在,看下一個(gè)例子:

let a1 = 10; let a2 = "10";console.log(a1 !== a2); console.log(a1 != a2);

Output

輸出量

true false

In the above comparison, we're comparing two same values due to which the != operator returns us false but we're comparing two different types due to which the !== operator returns true. Thus we can say that the !== operator not only checks for the values but also for the type of the variables being compared. Since in this case both the variables had different types, they were evaluated as unequal by the !== operator and hence we got the true result.

在上面的比較中,我們正在比較兩個(gè)相同的值,因?yàn)?strong>!=運(yùn)算符將其返回給我們false;但是,我們正在比較兩個(gè)不同的類型,由于它們使!==運(yùn)算符返回了true 。 因此,可以說!==運(yùn)算符不僅檢查值,還檢查要比較的變量的類型。 由于在這種情況下,兩個(gè)變量都具有不同的類型,因此!==運(yùn)算符將它們視為不相等,因此我們得到了真實(shí)的結(jié)果。

let ob1 = { name: "Mario" } let ob2 = { name: "Mario" }console.log(a!=b); console.log(a!==b);

Output

輸出量

true true

Both our objects are completely identical yet the != as well as the !== operator returns true indicating they're both unequal. Why is that so? This has something to do with the memory addressing of variables. Both the objects occupy completely different blocks of memory and are thus considered as two separate instances or two separate entities.

我們兩個(gè)對(duì)象都是完全相同的,但是!=!==運(yùn)算符返回true表示它們都不相等。 為什么呢? 這與變量的內(nèi)存尋址有關(guān)。 這兩個(gè)對(duì)象占用完全不同的內(nèi)存塊,因此被視為兩個(gè)單獨(dú)的實(shí)例或兩個(gè)單獨(dú)的實(shí)體。

let ob3 = ob1;console.log(ob1 != ob3); console.log(ob1 !== ob3);

Output

輸出量

false false

Since now ob3 occupies the same address as ob1, they're considered completely identical. Can you conclude which out of the != and !== does a more strict comparison than the other?

由于現(xiàn)在ob3與ob1占用相同的地址,因此它們被視為完全相同。 您是否可以得出結(jié)論,在!=!==中哪個(gè)比另一個(gè)更嚴(yán)格?

翻譯自: https://www.includehelp.com/code-snippets/difference-between-or-operator-in-javascript.aspx

javascript運(yùn)算符

總結(jié)

以上是生活随笔為你收集整理的javascript运算符_JavaScript中!=或!==运算符之间的区别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。