Wednesday, 6 December 2017

JavaScript | General guideline for addition operators

Operand1
Operand2
Operation
Number
Number
Addition
Boolean
Boolean
Addition
Boolean
Number
Addition
String
String
Concatenation
Number
String
Concatenation
String
Boolean
Concatenation

Few examples are given below
var bar = true;
console.log(bar + 0);
Boolean + Number à Addition
Output: 1

console.log(bar + "xyz");
Boolean + String à Concatenation
Output: truexyz

console.log(bar + true);
Boolean + Boolean à Addition
Output: 2

console.log(bar + false);
Boolean + Boolean à Addition
Output: 1


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...