JavaScript provides various ways to work with numbers. Here are some common operations and use cases:

  1. Basic Arithmetic Operations: You can perform basic arithmetic operations such as addition, subtraction, multiplication, and division.

    javascript
    let a = 5; let b = 3; let sum = a + b; let difference = a - b; let product = a * b; let quotient = a / b;
  2. Increment and Decrement: JavaScript provides shorthand notations for incrementing and decrementing variables.

    javascript
    let counter = 0; counter++; // Increment by 1 counter--; // Decrement by 1
  3. Exponential Notation: You can use the exponentiation operator (**) for raising a number to a power.

    javascript
    let result = 2 ** 3; // 2 raised to the power of 3 (2^3)
  4. Modulus Operator: The modulus operator (%) returns the remainder of a division operation.

    javascript
    let remainder = 10 % 3; // Result: 1 (remainder of 10 divided by 3)
  5. Math Object: JavaScript provides a Math object with many built-in methods for more advanced mathematical operations.

    javascript
    let x = Math.sqrt(25); // Square root let y = Math.random(); // Random number between 0 and 1 let z = Math.floor(3.14); // Round down to the nearest integer
  6. Conversion: You can convert strings to numbers using parseInt() or parseFloat().

    javascript
    let numString = "42"; let num = parseInt(numString); // Converts to integer
  7. Number Methods: Numbers in JavaScript are primitive values, but you can use methods on number literals by converting them to objects using the Number constructor.

    javascript
    let num = 123; let numObject = new Number(num); let decimalString = numObject.toFixed(2); // Rounds to 2 decimal places
  8. NaN (Not a Number): You can use isNaN() to check if a value is not a number.

    javascript
    let value = "Hello"; let isNotANumber = isNaN(value); // true

These are just a few examples of how you can use numbers in JavaScript. Depending on your specific needs, you may encounter various other scenarios where numbers play a crucial role.