My friend told me that this code "is used to check the survival of Javascript object":
Example: I have 2 objects and each one has 2 property called 'a' and 'b'
var obj1 = {a:0,b:0}
var obj2 = {a:3,b:4}
With the obj1 with the value of all property is 0 and 'obj2' have child property's value is an integer and I make the 'obj1' to be the first operator of the checking expression then I have got result is "failed".
if((obj1.a && obj1.b)&& obj2){
document.write("success")
}else{
document.write("failed")
}
But otherwise if I make obj1 is the second operator then I have got result is "success" like this:
if((obj2.a && obj2.b)&& obj1){
document.write("success")
}else{
document.write("failed")
}
Can anyone explain to me why?
var obj1 = {a:0,b:0}
var obj2 = {a:3,b:4}
if((obj1.a && obj1.b)&& obj2){
document.write("success")
}else{
document.write("failed")
}
document.write("<br><br>")
if((obj2.a && obj2.b)&& obj1){
document.write("success")
}else{
document.write("failed")
}