Commutative Operation

Commutative Operation


  • In math, an operation is commutative if the order of the numbers used can be altered with the result remaining the same. For example, addition and multiplication are commutative operations, as shown below.

    2+3 = 5
    3+2 = 5
    2*3 = 6
    3*2 = 6

  • In contrast, subtraction and division are not commutative, because changing the order of the numbers involved changes the result of the calculation, as shown below.

    2-7 = -5
    7-2 = 5
    3/4 = 0.75
    4/3 = 1.3333333

  • In programming, this can be used with the logical AND or the logical OR operations to "short circuit" if a particular condition is met, so other possibilities are not tested. For example, with the AND operation, if the first condition is false, then the whole comparison must return false, so the remaining conditions are not evaluated. For example, a null value in JavaScript would create an error if it is used. A logical statement could be used to indicate if a value is null, then the remainder of the statement is not executed.

    var x = 0;
    if ( (y !== null) && (y > 0) && (y < 3) ) {
    window.alert(y * 4);
    }

  • In this case, if y is null, then the remainder of the statement is not executed. That prevents any errors with a null y variable and keeps additional processing from being done if y is null.


    What is an Operating System? » Computer Shortcut Keys and their Functions » Keyboard Function Keys » Computer Basics - Hardware - Software - Parts

    Short Stories for Kids - Moral Stories – English Short Stories for Children - Moral Stories for Kids -
    Stories for Kids - Funny Story for Kids - Scary Stories for Kids - Really Funny Short Stories - Bedtime Stories

    Proverb Stories
    Powerful Motivational Quotes for Students » Success Quotes » English Short Stories for Kids

    Cabin Crew Jobs & Career Advice » Secretary Job Description » Receptionist Job Description » Top 100 Interview Questions and Answers » How to Prepare for an Interview » How to Write a CV » How to Choose a Career » Computer Shortcut Keys and their Functions

    Scholarships in Australia » Scholarships in Austria » Scholarships in Belgium » Scholarships in Canada » Scholarships in Germany » Scholarships in Ireland » Scholarships in Italy » Scholarships in Japan » Scholarships in Korea » Scholarships in Netherlands » Scholarships in Switzerland » Scholarships in UK » Scholarships in USA

    Scholarships for Study in Africa » Scholarships for African Students » Undergraduate Scholarships » African Women Scholarships & Grants Scholarships for Study in Africa » Scholarships for African Students » Undergraduate Scholarships » African Women Scholarships & Grants Scholarships for Study in Africa » Scholarships for African Students » Undergraduate Scholarships » African Women Scholarships & Grants Short Stories for Kids - Moral Stories – English Short Stories for Children - Moral Stories for Kids - Stories for Kids - Funny Story for Kids - Scary Stories for Kids - Really Funny Short Stories - Bedtime Stories
    Proverb Stories
    Powerful Motivational Quotes for Students » Success Quotes »Scholarships in UK » Scholarships in USA Scholarships in UK » Scholarships in USA Scholarships in UK » Scholarships in USA Scholarships in UK » Scholarships in USA Scholarships in UK »

  • Click here to post comments

    Join in and write your own page! It's easy to do. How? Simply click here to return to Computer Basics FAQ.