This section provides an example of basic arithmetic operations in JavaScript. Arithmetic operations are fundamental to programming and JavaScript supports various arithmetic operators.
Basic Arithmetic Operators
Here are some common arithmetic operators in JavaScript:
- Addition (
+
): Adds two values together. - Subtraction (
-
): Subtracts the second value from the first. - Multiplication (
*
): Multiplies two values. - Division (
/
): Divides the first value by the second. - Modulus (
%
): Divides the first value by the second and returns the remainder.
Example
Below is an example of how to use these operators in JavaScript:
let a = 10;
let b = 5;
console.log(a + b); // Output: 15
console.log(a - b); // Output: 5
console.log(a * b); // Output: 50
console.log(a / b); // Output: 2
console.log(a % b); // Output: 0
Practice
To practice, try modifying the values of a
and b
in the example above and observe the results.
For more in-depth learning, you can explore JavaScript Basics.
Images
Here's an image of a simple calculator, which can be used to visualize arithmetic operations: