Answer the question
In order to leave comments, you need to log in
Incomprehensible Javascript behavior in simple situations. Explain
Of course, after C ++ it is difficult for me to find such errors in the code. But still: what explains this behavior of JS?
Example one. In both cases, true was expected :
Will accept the second one. An equality comparison of two date objects always returns false. However, <= and < return different values. Unclear.
var flag = true;
flag &= true;
alert(flag);//говорит "1"
var flag = true;
flag = flag && true;
alert(flag);//говорит "true"
alert(new Date == new Date);//говорит "false"
alert(new Date <= new Date);//говорит "true"
alert(new Date >= new Date);//говорит "true"
alert(new Date < new Date);//говорит "false"
alert(new Date > new Date);//говорит "false"
Answer the question
In order to leave comments, you need to log in
Maybe because
flag &= true;This
flag = flag & true;not at all
flag = flag && true;(count the number of ampersands).
var a = new Date; var b = a; alert(a == b); // true
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question