JavaScript

1. Java Script Module 2. World Wide Web (WWW) 3. Web Terms 4. NEED FOR SCRIPT 5. Introduction to Internet Programming 6. CLIENT SIDE and SERVER SIDE Scripting 7. Different Scripting Languages 8. Introduction to JavaScript 9. JavaScript and Security 10. How to Enable JavaScript 11. Advantages of Java Script 12. Limitations with JavaScript 13. Difference between JavaScript and JAVA 14. Difference between JavaScript and VBScript 15. JavaScript Development Tools 16. JavaScript Programming Techniques 17. JavaScript terms 18. Starting with JavaScript Programming step by step 19. Time to start JavaScript Programming 20. JavaScript Variables 21. JavaScript RESERVED WORDS 22. JavaScript Data Type 23. NUMBER DATA TYPE 24. BOOLEAN DATA TYPE 25. STRING DATA TYPE 26. NULL DATA TYPE 27. JavaScript Undefined DATA TYPE 28. JavaScript Operators 29. JavaScript Arithmetic Operators 30. JavaScript Logical Operators 31. JavaScript Comparison Operators 32. JavaScript String Operators 33. Bit Manipulation Operators 34. JavaScript Assignment Operators 35. JavaScript Conditional Operator 36. Conversion between JavaScript Data Types 37. Alert JavaScript function 38. confirm JavaScript function 39. prompt JavaScript function 40. JavaScript Statements 41. Single line & Multi-line Comments 42. JavaScrip If Statement 43. JavaScript if..else Statements 44. JavaScript If…else..if statement. 45. JavaScript For Statement 46. JavaScript For..in Statement: 47. JavaScript While Statement 48. JavaScript do while Statement: 49. JavaScript break and continue statement 50. JavaScript switch Statement: 51. JavaScript function() 52. JavaScript function with a Return Value 53. JavaScript with Statement 54. try, catch, and throw Statements 55. JavaScript ARRAY 56. JavaScript array of different data types 57. JavaScript ARRAY and Bubble sorting Program 58. JavaScript Array Methods 59. concate() method 60. every() method 61. filter() method 62. forEach() method 63. indexOf() method 64. Join() method 65. lastIndexOf() method 66. map() method 67. reduce() method 68. reduceRight() method 69. reverse() method 70. some() method 71. toSource() method 72. toString() method 73. pop() method 74. push() method 75. shift () method 76. slice () method 77. splice () method 78. sort() method 79. unshift() method 80. EVENT handling with JavaScript 81. onblur JavaScript Event 82. onchange JavaScript Event 83. onclick JavaScript Event 84. onDblClick JavaScript Event 85. onfocus JavaScript Event 86. onkeydown JavaScript Event 87. onkeyup JavaScript Event 88. Onkeypress JavaScript Event 89. onLoad JavaScript Event 90. onMousedown JavaScript Event 91. onMouseup JavaScript Event 92. Onmouseover JavaScript Event 93. onmouseout JavaScript Event 94. onMouseMove JavaScript Event 95. onReset JavaScript Event 96. onsubmit JavaScript Event 97. onUnload JavaScript Event 98. The Screen Object 99. JavaScript Interview Part1 100. JavaScript Interview Part2 101. JavaScript Interview Part3 102. JavaScript Interview Part4 103. JavaScript Interview Part5 104. JavaScript Interview Part6 105. JavaScript Interview Part7 106. JavaScript Interview Part8 107. JavaScript Interview Part9 108. JavaScript Interview Part10
Pr.Pg Next Pg

JavaScript Arithmetic Operators tutorials

  • Arithmetic operators are the most familiar operators because we use them every day to perform common mathematical calculations.

  • The mathematical operators supported by JavaScript are listed in the following table:

 

Operator

Description

Example

Result

+

Adds right operand to left operand and assign the result to left operand.

2+3

5

-

Subtracts right operand from left operand & assigns the result to the left operand.

6-4

2

*

Multiplier two operands and store the result in left operand.

3*4

12

/

Divide left operand by right and assign the result to the left operand

15/3

5

%

Divides left operand by right and assign the remainder to the left operand.

15%7

1

++

Pre increment (++A) of A=A+1 (Increment and then return value)

 

X=3, ++X

4

Post increment (A++) of A=A+1 (Return value and then increment)

 

X=3, X++

3

--

Pre decrement (--A) of A=A-1 (Decrement and then return value)

X=3, --X

 

2

Post decrement (A--) of A = A – 1 (Return value and then decrement)

X=3, X--

3

 

Example: JavaScript Example performs the basic arithmetic operations.
Output:

Two + Ten =12

Ten * Ten = 100

Ten / Two = 5

 

  • From the above example, we have created the variables are var two contain the value 2, similarly var ten contain the value 10, var linebreak for break between two lines, and var result contain the values of mathematical operation. It will produce the output which is shown in the output.

Example: JavaScript Example performs the basic arithmetic operations.
Output:

x-y= 10

x%y = 0

Pre Increment ox x (20) = 21

Post Increment of y (10) = 10

Example: JavaScript Example shows the increment and decrement operator.
Output:

Example of Post increment

20

20

21

 

Example of Pre increment

20

21

21

 

Example of Post decrement

10

10

9

 

Example of Pre decrement

10

9

9

 

  • If you observe first document.write statement write the output value of A as 20, then in next statement it will first write the output value of A i.e 20 and then it use post increment after execution of command by 1, so for third document.write statement value will be write the output as 21.

  • Same way for B variable, first document.write statement, it will write the output value of B as 20, but in next document.write statement, before writing value, we have used pre increment (before execution), so it will write the output as 21. For third document.write statement value remains 21 only.

  • If you observe first document.write statement write the output value of x as 10, then in next statement it will first write the output value of x i.e 10 and then it use post decrement after execution of command by 1, so for third document.write statement value will be write the output as 9.

  • Same way for y variable, first document.write statement, it will write the output value of y as 10, but in next document.write statement, before writing the value, we have used pre decrement (before exeucition), so it will write the output as 9. For third document.write statement value remains 9 only.


Pr.Pg border                                              Next Pg