-5
var a=new Number(6);

var b=new Object(6);
a===b;  //false

I just do not understand why a===b return false. It has same type and come from same instance.

Yushi Cui
  • 1
  • 2

2 Answers2

1

Those are objects you cannot compare by value . The objects are compared by their reference .

var a=new Number(6);

var b=new Object(6);

var c=new Number(6);

var d = a;

a === b;  //false
a == c; // false
b == c;//false
a == d;//true

Those are primitives any you can compare by value . Primitives like strings and numbers are compared by their value.

var a= Number(6);
var b= Number(6);
a == b //true
a === b //true
Vladu Ionut
  • 8,075
  • 1
  • 19
  • 30
0

In JS or whatever,

== chracters control for value. For example;

var a = "1";
var b = 1;

a == b: return true

=== chracters control value and type. For example;

a === b: return false