Increment/Decrement Operators for String, Boolean, Floating-point and Object

OperandActionReturn Type
String with valid number valueconvert to number and do the calculationnumber
String with invalid number valueconvert string to NaNnumber
Boolean false valueconvert to 0 and do the calculationnumber
Boolean true valueconvert to 1 and do the calculationnumber
Floating-point valueadd or subtract 1number
Objectcall valueOf method and do the calculation. If the result is NaN call toString methodnumber
 
<!DOCTYPE html>
<html>
<head>
    <title>Operator Example</title>
    <script type="text/javascript">

        var s1 = "2"; 
        var s2 = "A"; 
        var s3 = "2.1"; 
        var s4 = "0xAA"; 
        var b  =  true; 
        var b2 = false; 
        var f  = 1.1; 
        var o  = { 
            valueOf: function() { 
               return 10; 
            } 
        }; 
        
        document.writeln(s1);
        document.writeln(s2);
        document.writeln(s3);
        document.writeln(s4);
        document.writeln(b);
        document.writeln(b2);
        document.writeln(f);
        document.writeln(o);
        
        s1++; 
        s2++; 
        s3++; 
        s4++; 
        b++; 
        b2++; 
        f++; 
        o++;

        document.writeln(s1);
        document.writeln(s2);
        document.writeln(s3);
        document.writeln(s4);
        document.writeln(b);
        document.writeln(b2);
        document.writeln(f);
        document.writeln(o);
        
    </script>

</head>
<body>
  
</body>
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    Language Basics  

Operators:
  1. JavaScript Operators
  2. Increment/Decrement Operators
  3. Increment/Decrement Operators for String, Boolean, Floating-point and Object
  4. Unary Plus and Minus
  5. Bitwise Not operator
  6. Bitwise AND
  7. Bitwise OR
  8. Bitwise XOR
  9. Left Shift
  10. Signed Right Shift
  11. Unsigned Right Shift
  12. Logical NOT
  13. Logical AND
  14. Logical OR
  15. Multiply
  16. Divide
  17. Modulus
  18. Add
  19. Subtract
  20. Relational Operators
  21. Equal and Not Equal
  22. Identically Equal and Not Identically Equal
  23. Conditional Operator
  24. Assignment Operators
  25. Comma Operator