Example 2.6: Concatenation
var foo = 'hello';
var bar = 'world';
console.log(foo + ' ' + bar); // 'hello world'
Example 2.7: Multiplication and division
2 * 3;
2 / 3;
Example 2.8: Incrementing and decrementing
var i = 1;
var j = ++i; // pre-increment: j equals 2; i equals 2
var k = i++; // post-increment: k equals 2; i equals 3
Operations on Numbers & Strings
In JavaScript, numbers and strings will occasionally behave in ways you might not expect.
Example 2.9: Addition vs. concatenation
var foo = 1;
var bar = '2';
console.log(foo + bar); // 12. uh oh
Example 2.10: Forcing a string to act as a number
var foo = 1;
var bar = '2';
// coerce t
We’ve updated our privacy policy so that we are compliant with changing global privacy regulations and to provide you with insight into the limited ways in which we use your data.
You can read the details below. By accepting, you agree to the updated privacy policy.