Arithmetic operators
Open the developer console to see the result
Arithmetic operators: ************************** x = 10 y = 3 x + y = 13 x - y = 7 x * y = 30 x / y = 3.3333333333333335 x % y = 1 x ** y = 1000
Post increment (x++): *************************************** x = 10 x starts at 10 x++ = 10 x has not incremented yet! x = 11
Pre increment (++y): *************************************** y = 3 y starts at 3 ++y = 4 y has has already been incremented y = 4
let x = 10;
let y = 3;
const example = `Arithmetic operators:
**************************
x = ${x}
y = ${y}
x + y = ${x + y}
x - y = ${x - y}
x * y = ${x * y}
x / y = ${x / y}
x % y = ${x % y}
x ** y = ${x ** y}
`;
console.log(example);
document.querySelector('pre').innerHTML = example;
// post increment
const post = `Post increment (x++):
***************************************
x = ${x} x starts at 10
x++ = ${x++} x has not incremented yet!
x = ${x}
`;
console.log(post);
document.querySelector('pre:nth-of-type(2)').innerHTML = post;
// pre increment
const pre = `Pre increment (++y):
***************************************
y = ${y} y starts at 3
++y = ${++y} y has has already been incremented
y = ${y}
`;
console.log(pre);
document.querySelector('pre:nth-of-type(3)').innerHTML = pre;