JavaScript If statement condition with no operator? What does it do?

前端 未结 4 1479
天命终不由人
天命终不由人 2021-01-01 17:10

I am used to if statements having a condition where ( x < y ) or ( x == y ). But in cases where there is no operator, what does the if statement check exactly? i.e. in th

4条回答
  •  温柔的废话
    2021-01-01 17:42

    This checks whether there exists a property on window called XMLHttpRequest whose "truthiness" is true. Javascript interprets a variety of values as true: true, any non-0 numeric value, any non-null object reference, or (I think) any non-empty string.

    In this case, the code is testing whether the browser supports the XMLHttpRequest property, which is the constructor function for an object that sends asynchronous requests to the server in the above-mentioned browsers. If the browser defines this function, the if statement will evaluate to true.

提交回复
热议问题