Web development
Numbers, Strings, and Conversion
Updated Oct 28, 2026
JavaScript distinguishes numbers from strings. The plus operator adds numbers but can concatenate when a string is involved. Convert deliberate numeric input with Number and check for invalid results
What you’ll learn
Learn to apply numbers, strings, and conversion in a practical situation.
Explanation
JavaScript distinguishes numbers from strings. The plus operator adds numbers but can concatenate when a string is involved. Convert deliberate numeric input with Number and check for invalid results with Number.isNaN. Empty strings and other inputs have special conversion behaviour, so validate the input first.
JavaScript បែងចែកលេខ និងអត្ថបទ។ សញ្ញា + អាចបូកលេខ ឬភ្ជាប់អត្ថបទ។ ពិនិត្យទិន្នន័យជាមុន ហើយប្រើ Number ដើម្បីបម្លែងនៅពេលសមស្រប។
Worked example
2 + 3 gives 5; "2" + 3 gives "23". Number("2") + 3 gives 5.
Practice
- What does "2" + 3 produce?
- Apply the idea to an example of your own and explain your choice.
Answers and guidance
Show answers / បង្ហាញចម្លើយ
- The string "23", because the number is converted to text for concatenation.
- Answers vary. Compare your example with the explanation and check each step.
Quick recap
JavaScript distinguishes numbers from strings.