JavaScript Adding Booleans

后端 未结 3 606
眼角桃花
眼角桃花 2020-12-10 02:23
console.log(true+true); //2
console.log(typeof(true+true)); //number
console.log(isNaN(true+true)); //false

Why is adding together 2 boolean types

3条回答
  •  情深已故
    2020-12-10 03:00

    Javascript is loosely typed, and it automatically converts things into other things to fit the situation. That's why you can do var x without defining it as an int or bool

    http://msdn.microsoft.com/en-us/library/6974wx4d(v=vs.94).aspx

提交回复
热议问题