DEV Community

Cover image for A Gentle Introduction To The ++ Operator In Javascript
Alan Chang
Alan Chang

Posted on

A Gentle Introduction To The ++ Operator In Javascript

JavaScript '+' operator can be used in many different ways. 🤯

let x = "3";

console.log(typeof x)
// expected output: "string"

console.log(3 + x);
// expected output: "33"

console.log(+x + 3);
// expected output: 6

console.log(3 + + x);
// expected output: 6

console.log(3+ +x);
// expected output: 6

console.log(x++);
// expected output: 3

console.log(x++);
// expected output: 4

console.log(++x);
// expected output: 6

console.log(x);
// expected output: 6

console.log(typeof x);
// expected output: "number"
Enter fullscreen mode Exit fullscreen mode

Comment below if you have another interesting operation with '+' operator 😎

Top comments (0)