JS-019

Beginner3 min~3 min read#plus#addition#string
Plus Operator +
Adds numbers or joins text
Goal
Understand how the + operator works with numbers and strings.
Explanation
- The + operator can do two different jobs.
- If both values are numbers, it adds them.
- If at least one value is a string, it joins the text together.
- So the same operator can behave differently.
- JavaScript decides which mode to use on its own.
Analogy
Imagine a universal glue. It can either put two numbers together, or stick two pieces of text side by side.
Code
console.log(5 + 3);
console.log("Hello" + "!");Result: 8 Hello!
Common mistake
Beginners often expect + to always add numbers. If one of the values is a string, JavaScript will concatenate text instead.
Remember
- ✦ + adds numbers.
- ✦ + joins strings.
- ✦ The behavior depends on the data types.
Quick Quiz
What does "5" + 3 return?