Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок+ 6
Why b?not a?
var a = new String("hello"); var b = new String("hello"); if(a === b) { alert("a"); } else { alert("b"); }
6 ответов
+ 3
There, it works.
https://code.sololearn.com/WP58do6lXCR0/?ref=app
+ 3
because 'a' is only a reference to an object and 'b' also.
They have the same values (a and b), right, but the object exists 2 times, and both have a different adress in the RAM.
Like you compare if(0xff6384 === 0xaa6384) I would say 🤔
But maybe I'm wrong!
Whats also funny, try to compare [] with [] 😂
if([] == []){
//this will never executed
}
+ 1
A and b aren't the same object.
Using ==, the output is "a".
+ 1
Sorry, using ==, it doesn't work...
🤔I will try to give you a correct answer...
+ 1
thanks a lot ^_^, l was comparing objects:D
+ 1
The content is equal but the object is different. Use:
(a.valueOf === b.valueOf)