javascript - problem with an operator operation
怪我咯
怪我咯 2017-05-19 10:33:27
0
2
386

If n and guard do not exist, n==null is true, and guard is undefined in the ternary operator. If the Boolean value is converted to false, it will be equal to n, that is, the final return is undefined.
But why does it return 1?

var test=function(array,n,guard){
    return (n==null || guard ? 1 : n); 
};
console.log(test([]));//1
怪我咯
怪我咯

走同样的路,发现不同的人生

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!