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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈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…