javascript運算符_JavaScript中!=或!==運算符之間的區別

javascript運算符

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.

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

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都具有不同的值,所以我們從不等式中得到了真實的結論。

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.

當然,在上述情況下,因為兩者都具有相同的值!=運算符將返回false 。 因此,可以說!=運算符檢查要比較的兩個變量是否具有相同的值或具有相同的值。 如果沒有,則返回true和false,否則如上面兩個示例所示。

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:

我們已經比較了兩個完全不同的變量,它們存儲相同的值,并且兩個比較表達式都正確。 現在,看下一個例子:

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.

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

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.

我們兩個對象都是完全相同的,但是!=!==運算符返回true表示它們都不相等。 為什么呢? 這與變量的內存尋址有關。 這兩個對象占用完全不同的內存塊,因此被視為兩個單獨的實例或兩個單獨的實體。

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?

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

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

javascript運算符

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379805.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379805.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379805.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

實訓09.09:簡單的彩票系統(機選多注)

package wsq; import java.util.Random; import java.util.Scanner;//機選多注 public class MoreCaiPiao {public static void main(String[] args) {// 定義二維數組 存儲多注彩票int[][] numArray new int[5][7];/** 二維數組中 未賦值之前的元素值都為0 { {0,0,0,0,0,0,0}…

項目組的激勵策略

我們經常會采取一獎勵措施,來激發大家工作的積極性,從而達到提高工作效率的目的。那么我們應該對項目組中的那些類型的人實施激勵呢?項目的實踐過程中,筆者認為有兩類人需要給予正面的獎勵。一,能夠主動思考&#xff0…

zk中的Datebox中得到Timestamp

String formatDate sdf.format(datebox.getValue()); para.setCreate_time(Timestamp.valueOf(formatDate)); 轉載于:https://www.cnblogs.com/avenxia/archive/2012/04/15/2450052.html

定時器--STM32f4--HAL

基本概念 STM32中有三種定時器,高級定時器,通用定時器,基本定時器,具體如下圖: 發生如下事件將產生中斷/DMA 更新:計數器向上溢出/向下溢出,計數器初始化觸發事件:計數器啟動、停…

實訓09.09:簡單的彩票系統(自選多注)

package wsq; import java.util.Scanner; public class CustomCaipiao {public static void main(String[] args) {/** 用戶自選彩票數字: 1.使用scanner來輸入彩票號碼! 2.直接寫成自選多注,注數由用戶輸入決定;* 3.紅球值1-33,不重復;藍球值1-16;*/// 定義二維數組 存儲所有的…

c ++查找字符串_C ++類和對象| 查找輸出程序| 套裝4

c 查找字符串Program 1: 程序1&#xff1a; #include <iostream>using namespace std;class Sample {int X;int* const PTR &X;public:void set(int x);void print();};void Sample::set(int x){*PTR x;}void Sample::print(){cout << *PTR - EOF << …

ASP.NET 泛型類型 Dictionary操作

protected void Page_Load(object sender, EventArgs e){//泛型Dictionary Dictionary<string, string> dit new Dictionary<string, string>();dit.Add("13", "張三");dit.Add("22", "李四");Response.Write("總數…

獨立看門狗---STM32----HAL

基本概念 看門狗解決的問題是什么&#xff1f; 在系統跑飛&#xff08;程序異常執行&#xff09;的情況&#xff0c;是系統復位&#xff0c;程序重新執行。 獨立看門狗適應用于需要看門狗作為一個在主程序之外能夠完全獨立工作&#xff0c;并且對時間精度要求低的場合。 工…

實訓09.09:簡單的彩票系統(注冊信息)

package wsq; import java.util.Scanner;//本文件負責注冊用戶信息 /*用戶注冊信息:1.要求設置賬號和密碼,使用字符串數組2.賬號名不能重復3.密碼需要輸入兩次,兩次密碼輸入一致4.滿足賬號名不重復.且兩次密碼一致,即為注冊成功!!將信息添加到字符串數組中String[][] users ne…

【轉】JAVA生成縮略圖

方法1&#xff1a;[第一種方法比后一種生成的縮略圖要清晰] import javax.imageio.ImageIO;import java.awt.image.BufferedImage;import java.awt.image.ColorModel;import java.awt.image.WritableRaster;import java.awt.*;import java.awt.geom.AffineTransform;import jav…

javascript寫入_如何在JavaScript中寫入HTML元素?

javascript寫入寫入HTML元素 (Writing into an HTML element) To write string/text into an HTML element, we use the following things: 要將字符串/文本寫入HTML元素&#xff0c;我們使用以下內容&#xff1a; There must be an HTML element like paragraph, span, div e…

大話設計模式之設計模式遵循的七大原則

最近幾年來&#xff0c;人們踴躍的提倡和使用設計模式&#xff0c;其根本原因就是為了實現代碼的復用性&#xff0c;增加代碼的可維護性。設計模式的實現遵循了一些原則&#xff0c;從而達到代碼的復用性及增加可維護性的目的&#xff0c;設計模式對理解面向對象的三大特征有很…

IIC通信---EEPROM24C02---STMF4

IIC通信協議 IIC是同步半雙工通信&#xff0c;一個數據線SDA和一個時鐘SCL線&#xff0c;可以接受和發送數據。在CPU與被控IC之間、IC與IC之間進行雙向傳送。 空閑狀態 IIC總線的SDA和SCL兩條信號線同時處于高電平時&#xff0c;規定為總線的空閑狀態。 起始信號 當SCL為高…

實訓09.08:簡單的算法練習

/*final 關鍵字 修飾的變量值 后期不可更改 相當于定義常量常量 &#xff1a;不可更改*/final int a 10;//a 20; 報錯的值不可更改&#xff01;/*輸入函數* */System.out.println("請輸入數字&#xff1a;");Scanner scanner new Scanner(System.in);int b…

讓自己閃亮

轉載于:https://www.cnblogs.com/Gigabyte/archive/2009/01/03/you_can_shine.html

Java中的wait()和sleep()方法之間的區別

Java中的wait()和sleep()方法 (wait() and sleep() methods in Java) First, we will see how wait() method differs from sleep() method in Java? 首先&#xff0c;我們將看到wait()方法與Java中的sleep()方法有何不同&#xff1f; wait()方法 (wait() Method) This metho…

離線使用iPhone SDK文檔的方法

在使用Xcode進行iPhone編程時&#xff0c;有時需要參考iPhone SDK的文檔&#xff0c;不過每次ControlClick后&#xff0c;Xcode都會試圖連接Internet&#xff0c;進行在線讀取。有什么方法能夠把資料下載到硬盤上進行離線閱讀嗎&#xff1f; 答案是肯定的。首先去Xcode的Prefer…

遠程連接sql server 2000服務器的解決方案

遠程連接sql server 2000服務器的解決方案2007-04-07 11:29遠程連接sql server 2000服務器的解決方案   一 看ping 服務器IP能否ping通。   這個實際上是看和遠程sql server 2000服務器的物理連接是否存在。如果不行&#xff0c;請檢查網絡&#xff0c;查看配置&#xff0c…

實訓09.10:HTML簡單表格設計

<!DOCTYPE html> <html><head><meta charset"UTF-8"><title>燕雨簡歷</title></head><body><table border"" cellspacing"" cellpadding"" width"400px" height"6…

LCD顯示實驗----STM32f4--HAL

步驟 LCD初始化 LCD_Init(); //LCD初始化此函數在lcd.c文件里面 2. 設置LCD背景顏色 LCD_Clear(WHITE);此函數在lcd.c文件里面 3. 設置字體顏色 POINT_COLORRED; 寫入要顯示的字體 LCD_ShowString(10,80,240,24,24,"LTDC TEST");LCD_ShowSt…