Working with Strings and Numbers


Strings and numbers are two of the most commonly used data types in JavaScript. Strings are used to store text, while numbers are used to store numeric values.

In real programs, developers often work with both at the same time. For example, showing a user’s name (string) with their score (number) requires combining these two data types correctly.

Understanding how to work with strings and numbers is essential for building dynamic and interactive applications.

Common Operations with Strings and Numbers

With strings, you can:

  • Combine text using +
  • Find length of text
  • Convert text to uppercase or lowercase

With numbers, you can:

  • Add, subtract, multiply, and divide
  • Compare values
  • Perform calculations in programs

This example joins two strings to create a full name. The + operator is used here for string concatenation.

This is a very common operation in real applications such as user profiles and greeting messages.

This example multiplies two numbers to calculate a total amount. JavaScript uses normal math operators for number calculations.

Such logic is used in shopping carts, billing systems, and financial applications.

This example shows how strings and numbers work together to create meaningful messages.

Mastering strings and numbers helps you build programs that display useful information, perform calculations, and interact with users effectively.