Geek Slack

Introduction to JavaScript
    About Lesson




    JavaScript Numbers


    JavaScript Numbers

    Numbers in JavaScript are represented using the number data type. They can be integers or floating-point numbers.

    Integer Numbers

    Integer numbers are whole numbers without any decimal points.

    Example:

    const integerNumber = 42;

    Floating-Point Numbers

    Floating-point numbers, or floats, are numbers with decimal points.

    Example:

    const floatNumber = 3.14;

    Basic Arithmetic Operations

    You can perform various arithmetic operations on numbers in JavaScript.

    Example:

    const num1 = 10;
    const num2 = 5;
    
    console.log(num1 + num2); // Addition: 15
    console.log(num1 - num2); // Subtraction: 5
    console.log(num1 * num2); // Multiplication: 50
    console.log(num1 / num2); // Division: 2
    console.log(num1 % num2); // Modulus: 0

    NaN (Not a Number)

    JavaScript returns NaN when an operation results in a value that is not a valid number.

    Example:

    const result = 10 / "apple";
    console.log(result); // Output: NaN

    Understanding JavaScript numbers and arithmetic operations is fundamental for performing mathematical calculations and building applications that involve numerical data.