【Foreword】
Seeing a js interview question is very basic, but it is still easy to confuse newcomers. Record it here and emphasize it in future lectures
The following is my personal understanding, if there is any misunderstanding, please correct me
【main body】
When learning js, you should have learned the boolean value, and general textbooks will give relevant explanations, such as
boolean has two cases true and false and 0 and 1, 0 for false, 1 for true
So here's a question
Interview questions:
var request = 1>2; if(request==666){ console.log('aaa') }else{ console.log('bbb') }
The answer is: bbb, which reminds me of a student who asked me before about Boolean = 2
【Analysis】
The easy confusion here is the judgment condition ( boolean=666 )
In fact, just remember that 0 is false, and non-0 is true. And 1=true in the tutorial is just a commonly used value, don't confuse it here
.