JavaScript Comparison and Logical Operators

Ref:http://www.w3schools.com/js/js_comparisons.asp

 1 var r = 1;

 2 var result = r || 2;

 3 console.log(result);

 4 //output: 1

 5 

 6 r = 0;

 7 result = r || 2;

 8 console.log(result);

 9 //output: 2

10 

11 r = 0;

12 result = r || "string";

13 console.log(result);

14 //output: string

 

你可能感兴趣的:(JavaScript)